AJAX-poll met ip-log

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

AstroVersum

AstroVersum

20/11/2006 22:10:00
Quote Anchor link
Hallo,

Ik zit al de hele middag te puzzelen met een ajax-poll script die ik van het internet gedownload heb. Ik wil proberen ipv cookies ip-logging te gebruiken. Hoe en waar moet ik dit doen (beginner in scripting met php, en newby ajax)

Het gebruikt mysql dus kan met databases werken. Er zijn ook nog een paar andere pagina's, maar ik denk dat het in deze twee bestanden moet zitten.

ajax-poller
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?

require_once("dbConnect.php");

?>


<HTML>
<HEAD>
    <?
    @include($_SERVER['DOCUMENT_ROOT']."/config/metatags.inc");
    ?>
    
    <title>Ajax poller</title>
    <link rel="stylesheet" href="css/ajax-poller.css" type="text/css">
    <script type="text/javascript" src="js/ajax.js"></script>
    <script type="text/javascript" src="js/ajax-poller.js">    </script>

</HEAD>
<BODY>

<form action="<? echo $_SERVER['PHP_SELF']; ?>" onsubmit="return false" method="post">
<div id="mainContainer">
    <div id="mainContent">
    
        <?
        $pollerId
= 6;    // Id of poller
        ?>

        <!-- START OF POLLER -->
        <div class="poller">
        
            <div class="poller_question" id="poller_question<? echo $pollerId; ?>">
            <?            
            
            
            // Retreving poll from database
            $res = mysql_query("select * from poller where ID='$pollerId'");    
            if($inf = mysql_fetch_array($res)){
                echo "<p class=\"pollerTitle\">".$inf["pollerTitle"]."</p>";    // Output poller title
                
                $resOptions = mysql_query("select * from poller_option where pollerID='$pollerId' order by pollerOrder") or die(mysql_error());    // Find poll options, i.e. radio buttons
                while($infOptions = mysql_fetch_array($resOptions)){
                    if($infOptions["defaultChecked"])$checked=" checked"; else $checked = "";
                    echo "<p class=\"pollerOption\"><input$checked type=\"radio\" value=\"".$infOptions["ID"]."\" name=\"vote[".$inf["ID"]."]\" id=\"pollerOption".$infOptions["ID"]."\"><label for=\"pollerOption".$infOptions["ID"]."\" id=\"optionLabel".$infOptions["ID"]."\">".$infOptions["optionText"]."</label></p>";    
            
                }
            }
            
            ?>
            
            <a href="#" onclick="castMyVote(<? echo $pollerId; ?>,document.forms[0])"><img src="images/vote_button.gif"></a>
            </div>
            <div class="poller_waitMessage" id="poller_waitMessage<? echo $pollerId; ?>">
                Getting poll results. Please wait...
            </div>
            <div class="poller_results" id="poller_results<? echo $pollerId; ?>">
            <!-- This div will be filled from Ajax, so leave it empty --></div>
        </div>
        <!-- END OF POLLER -->
        <script type="text/javascript">
        if(useCookiesToRememberCastedVotes){
            var cookieValue = Poller_Get_Cookie('dhtmlgoodies_poller_<? echo $pollerId; ?>');
            if(cookieValue && cookieValue.length>0)displayResultsWithoutVoting(<? echo $pollerId; ?>); // This is the code you can use to prevent someone from casting a vote. You should check on cookie or ip address
        
        }
        </script>
        
    </div>
    <div class="clear"></div>
</div>
</form>

</BODY>
</HTML>


Stemverwerking (ajax-poller-cast-vote-php):
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?

if(isset($_GET['pollId'])){
    
    require_once("dbConnect.php");
    
    $optionId = false;
    
    if(isset($_GET['optionId'])){
        $optionId = $_GET['optionId'];
        $optionId = preg_replace("/[^0-9]/si","",$optionId);
    }

    $pollId = $_GET['pollId'];
    $pollId = preg_replace("/[^0-9]/si","",$pollId);
    

            
    // Insert new vote into the database
    // You may put in some more code here to limit the number of votes the same ip adress could cast.

    
    if($optionId)mysql_query("insert into poller_vote(optionID,ipAddress)values('".$optionId."','".getenv("REMOTE_ADDR")."')");
    
    // Returning data as xml
    
    echo '<?xml version="1.0" ?>';
    
    $res = mysql_query("select ID,pollerTitle from poller where ID='".$pollId."'");
    if($inf = mysql_fetch_array($res)){
        echo "<pollerTitle>".$inf["pollerTitle"]."</pollerTitle>\n";
        
        $resOptions = mysql_query("select ID,optionText from poller_option where pollerID='".$inf["ID"]."' order by pollerOrder") or die(mysql_error());
        while($infOptions = mysql_fetch_array($resOptions)){
            echo "<option>\n";
            echo "\t<optionText>".$infOptions["optionText"]."</optionText>\n";                    
            echo "\t<optionId>".$infOptions["ID"]."</optionId>\n";                    
            
            $resVotes = mysql_query("select count(ID) from poller_vote where optionID='".$infOptions["ID"]."'");
            if($infVotes = mysql_fetch_array($resVotes)){
                echo "\t<votes>".$infVotes["count(ID)"]."</votes>\n";                            
            }
                                        
            echo "</option>";                
            
        }                
    }

    exit;

}
else{
    echo "No success";
    
}


?>


Kunnen jullie mij helpen? Of eventueel andere mooie ajax-script met iplogging.

Alvast bedankt,
Gewijzigd op 01/01/1970 01:00:00 door AstroVersum
 
PHP hulp

PHP hulp

19/11/2024 01:39:51
 
PHP Newbie

PHP Newbie

20/11/2006 22:14:00
Quote Anchor link
[ligt offtopic]
Quote:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?
        @include($_SERVER['DOCUMENT_ROOT']."/config/metatags.inc");
    ?>


In dit soort gevallen moet je de foutmelding niet onderdrukken met een @-je, maar juist voorkomen d.m.v. de functie file_exists, zodat je er dan zelf even wat nee kunt zetten, een standaard meta-tag of zo.
 
AstroVersum

AstroVersum

21/11/2006 14:59:00
Quote Anchor link
Niemand :(
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.