dongzang5815 2014-11-04 18:52
浏览 47
已采纳

PHP重定向或cookie,不是在Godaddy上工作,而是在localhost上工作

So i've just uploaded my php to godaddy, except the redirects which were working have now stopped. There's supposed to be no difference between how code works on a live server to offline so i don't understand what's changed.

Here is a sample of the code which isn't working

The header link with the logout hyperlink which as far as i can tell acts as a hyperlink should

<div id="header">
           <div>
            <a href="index.php">Home</a> 
                <div id="loginreglink">
                <a href="Logout.php">Log Out</a>
                </div>
           </div>
          </div> 

The actual Logout page (logout.php)

<?php

require_once ('Connection.php');

header('Refresh: 0;');

            if (!isset($_COOKIE['Username'])){
                require ('LoginFunctions.inc.php');
                redirect_user();
            } else {
                setcookie('Username', '', time()-60*60*24*90, '/', '', 0, 0);
                require ('RedirectPage.php');
                redirect_user();
            }


?>

RedirectPage.php (the next page which should link to, immediately after access of the logout page)

<?php
            require ('index.php');
            redirect_user();
?>

Which then immediately links back to index, however the user should be logged out. This isn't happening.

What happens is the page redirects to index (as it should) presumably using the following sequence, which leads me to think that the redirects are working, but the user isn't logged out. The cookie isn't removed. I don't really understand why it isn't though because it does work through netbeans on localhost.

  • 写回答

1条回答 默认 最新

  • dongliu0823 2014-11-04 19:00
    关注

    It's easy. Unset the cookie.

    if (!isset($_COOKIE['Username'])){
       require ('LoginFunctions.inc.php');
       redirect_user();
    } else {
       setcookie('Username', '', time()-60*60*24*90, '/', '', 0, 0);
       require ('RedirectPage.php');
       //add this
       unset($_COOKIE['Username'];
       //or use setcookie and make the time to expire in the past and just put an empty value like
       $cookie_name = "Username";
       $cookie_value = "";
       $time = -3600;
       setcookie($cookie_name, $cookie_value, $time, "/");
       redirect_user();  
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵