Passing GET variables using header in PHP

2019-05-22 18:08发布

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条回答
Fickle 薄情
2楼-- · 2019-05-22 18:27

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.

查看更多
登录 后发表回答