dongshai2022 2014-04-10 12:16 采纳率: 100%
浏览 37

Wordpress中PHP代码的无限重定向循环

I have a PHP script which I will post below. It is a voting website, and my client only wants one user to be able to vote once based on their cookies and IP address.

After voting once, if the cookie or IP is detected as the same they are redirected to a fake voting pg which allows multiple votes. The browser loops between both the legal and duplicate vote pages.

Here is the code, I only added in the exit and die functions after getting this error and seeing online that might be the cause - however adding those functions made no difference.

$q = mysql_query("SELECT * FROM votelog");

while($row = mysql_fetch_array($q))
{
     if(($ip = $_SERVER['REMOTE_ADDR']) == $row['ip'])
     {
            $duplicateIP = true;
     }//end if

     if(($row['pollid'] == 8))
     {
         $duplicatePoll = true;
      }//end if
   }//end while

   //check cookies
   if(isset($_COOKIE['poll']))
   {
       $cookieCheck = true;
    }//end if

     if((($duplicateIP == true) && ($duplicatePoll == true)) or ($cookieCheck == true)) 
     {
         show this pg
      }//end if
      else
      {
            echo '<meta http-equiv="refresh" content="0; url=/polls/legit" />'; //redirect to legal pg
      exit();
      die();

       }//end else

Any ideas? The other page is the same except that the if and else are switched, like this:

     if((($duplicateIP == true) && ($duplicatePoll == true)) or ($cookieCheck == true)) 
     {
          echo '<meta http-equiv="refresh" content="0; url=/polls/dupe" />'; //redirect to duplicate
      exit();
      die();
      }//end if
      else
      {
          show this pg
       }//end else

P.S - I'm operating in a Wordpress environment

  • 写回答

1条回答 默认 最新

  • douao3636 2014-04-10 14:59
    关注

    It is hard to guess whats going on there. But if your code is fine, i would expect that you have an caching issue.

    Setting the headers (header()) correct, would help to solve that issue. But be carefull, you can make it more worse with setting wrong headers.

    So an easy workaround could be to add an ?time() to your url. So the redirected URL would change each second.

    echo '<meta http-equiv="refresh" content="0; url=/polls/dupe?'.time().'" />'; //redirect to duplicate
    

    Just a side note:

    exit();
    die(); // this will never reached, as exit() and die() is the same
    

    About exit() and die()

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题