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.

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

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?