在PHP中使用标头传递GET变量 [英] Passing GET variables using header in PHP
问题描述
我为一个网站编写了仅限用户访问权限,当用户未登录时,仪表板重定向到登录页面。
<?php
session_start();
$ logged = $ _SESSION ['logged'];
if(!$ logged){
header(Location:http://www.someweb.com/system/login.php?logged_off = 1);
}
?>
但登录页面没有收到GET变量,请告诉我做错了什么? 使用 rel =nofollow> 标题位置 ,您应该致电 exit();
因为脚本的执行不会被终止。
圆括号()
是可选的, exit
是语言构造不是一个函数,而且他们实际上是一个坏主意(PHP存在更多的工作要做),这只是一个可怕的习惯。
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?
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.
这篇关于在PHP中使用标头传递GET变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!