我已经在核心PHP中创建了一个投票系统,并使用了cookie,以便一个人不能两次投票,并且代码可以在localhost上正常运行,但不能在实时服务器上运行。
我正在使用GoDaddy
托管,并且已将文件夹上传到我的主域中,路径为mydomain.com/election
<?php
include("connection.php");
if(isset($_COOKIE['vote']))
{
echo "<script>alert('You cannot vote again.');</script>";
exit();
}
else
{
if(isset($_POST['modi']))
{
$name = 'vote';
$value = '1';
setcookie($name, $value, time()+1*365*24*60*60, '/', 'technoamazon.com', 0);
$modi = mysqli_query($con, "update election set modi=modi+1");
if($modi)
{
echo "<script>alert('You have voted to Shri Narendra Modi.');</script>";
echo "<script>window.open('index.php','_self');</script>";
}
}
if(isset($_POST['rahul']))
{
$name = 'vote';
$value = '1';
setcookie($name, $value, time()+1*365*24*60*60, '/', 'technoamazon.com', 0);
$rahul = mysqli_query($con, "update election set rahul=rahul+1");
if($rahul)
{
echo "<script>alert('You have voted to Shri Rahul Gandhi.');</script>";
echo "<script>window.open('index.php','_self');</script>";
}
}
}
?>
以上代码在localhost中正常运行,但在服务器上不工作