echo" <html> <title>wang example</title> </head> <body> <p>Hello $FirstName $LastName, this is your visit number: $count</p> <p>Your email address is: $email</p> <body> <html>";
mysql_connect() or die ("Problem connecting to DataBase"); //update DB $query = "update info set count=$count where FirstName='$FirstName' and LastName='$LastName' and email='$email'"; $result = mysql_db_query("users", $query) or die ("Problems .... ");
} //End Existing cookie instructions
else { //Begin inctructions for no Cookie echo "<html> <head> <Title>Rafi's Cookie example</title> </head> <body> <a href="reg.php">Click Here for Site Registration</a> </body> </html>"; } //End No Cookie instructions ?>
注意:如果你用的是一个远程mysql服务器或unix服务器,你应用下面语句 mysql_connect ("server","username","password") or die ("Problem connecting to DataBase");
我们想检查是否一个被指定名字的cookie在html头部分传送,记住,php能转换可识别的cookie为相应的变量,所以我们能检查一个名为"Example" 的变量: <? if (isset($Example)) { //Begin instructions for existing Cookie ... } else { ... } 如果这个cookie存在,我们将计数器加一,并打印用户信息,如果这个cookie不存在,我们建议用户先注册 如果cookie存在,我们执行下面步骤: <? if (isset($Example)) { //Begin instructions for existing Cookie $info = explode("&", $Example); //split the string to variables $FirstName=$info[0]; $LastName=$info[1]; $email=$info[2]; $count=$info[3];