doucha4054 2018-09-13 16:55
浏览 227
已采纳

PHP - 具有302代码响应的setCookies问题

I get the following issue with this code : The localhost page caused too many redirections. Status code is 302 Found. After deleting last else, I come succesfull to my site with 200 OK respone but then $user is not defined.

if (empty($_GET['unique_user'])) {
  if (!empty($_COOKIE['unique_user_D_']) && mysqli_num_rows(mysqli_query($connection, "SELECT `id` FROM `users` WHERE `hash`='".myFunction($_COOKIE['unique_user_D_'])."' LIMIT 1"))!=0) {
    header('Location: ./?unique='.$_COOKIE['unique_user_D_']);
    exit();  
  }
  newUser($add);
}
else { 
  if (mysqli_num_rows(mysqli_query($connection, "SELECT `id` FROM `users` WHERE `hash`='".myFunction($_GET['unique_user'])."' LIMIT 1"))!=0) {
    $user=mysqli_fetch_array(mysqli_query($polaczenie, "SELECT * FROM `users` WHERE `hash`='".myFunction($_GET['unique_user'])."' LIMIT 1"));
    $unique=myFunction($_GET['unique_user']);
    setcookie('unique_user_D_',myFunction($_GET['unique']),(time()+60*60*24*365*5),'/');  
  }
  else {
    setcookie('unique_user_D_',false,1),'/');
    header('Location: ./');    
    exit();
  }
}
  • 写回答

1条回答 默认 最新

  • douhoujun9304 2018-09-13 18:13
    关注

    The reason is that you are calling:

    header('Location: ./');    
    exit();
    

    Which redirects the current page to the Location: ./ (HTTP Code 302) and I guess the Location is the same path as this code = leading to Too Many Redirects since you are always redirecting to the same page.

    Removing the code (header and exit) should solve your problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效