Passing GET variables using header in PHP

痞子三分冷 提交于 2019-12-07 20:11:32

问题


I'm coding a "users-only" access for a site, and when the user is not logged in the dashboard is redirecting to the login page.

<?php
session_start();
$logged= $_SESSION['logged'];

if(!$logged){
    header("Location:http://www.someweb.com/system/login.php?logged_off=1");
}

?>

but the login page is not receiving the GET variable, can you please tell what am I doing wrong?


回答1:


When using header location, you should call exit();

Why? Because the script's execution will not be terminated.

Parentheses () are optional, exit is a language construct not a function, and they actually are a bad idea (PHP has more work to do if they exist), just a terrible habit I have.



来源:https://stackoverflow.com/questions/26264997/passing-get-variables-using-header-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!