Cookie无法在服务器上运行,但可以在localhost上完美运行,我该怎么办?

时间:2019-02-10 18:51:29

标签: php

我已经在核心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中正常运行,但在服务器上不工作

0 个答案:

没有答案