how would i make it so that a page can only be viewed once a day by a user?
i would get the ip addresss...
then how would i check it had not visited this page before today? adding all ips that visit the page into a MySQL table then checking cant eb the best way, surely?
how would i do this?
Moderator: General Moderators
ok well so far I've got this:
and i get " Array to string conversion on line 2" (this line: if( ! $_COOKIE("link") == "ok" ) )
why? whats wrong with my code?
Code: Select all
<?php
if( ! $_COOKIE("link") == "ok" )
{
$conn=mysql_connect("localhost","shaun","squall")
or die("Could not connect");
$rs = mysql_select_db("game", $conn)
or die("couldnt select database");
$sql="update game set strength= strength + 1 where id=1";
$rs=mysql_query($sql,$conn)
or die("could not execute query");
$sql="select id,name,strength from game where id=1";
$rs1=mysql_query($sql,$conn)
or die("could not execute query");
while( $row = mysql_fetch_array($rs1) )
{
$msg="You just clicked <b>".$row[name]."'s</b> secret link! " .$row[name]."'s strength has increased to <b>".$row[strength]."</b>";
}
setcookie("link","ok", time()+86400 );
}
else
{
$msg="You can only click this link once a day!";
}
?>
<html><head><title>Page</title></head>
<body>
<?php
echo($msg);
?>
</body></html>why? whats wrong with my code?
Use a database to record each IP/date/time/browser and possibly use [php_man]sessions[/php_man] aswell.
Sessions have an edge over cookies in this case, because it's better that the webmaster controls the information rather than the client to prevent double accessing.
Also that line is wrong because arrays use square brackets not parenthesis. Make it $_COOKIE['link'].
Sessions have an edge over cookies in this case, because it's better that the webmaster controls the information rather than the client to prevent double accessing.
Also that line is wrong because arrays use square brackets not parenthesis. Make it $_COOKIE['link'].