2014-02-07 77 views
0

我想检查我的一个网页的URL信息,如果用户已经正确登陆检查URL与PHP

例如,如果用户访问www.example.com/page.php?data=something

用户将比布尔查看页面

但如果用户访问www.example.com/page.php他被重定向

这是我当前的代码

$checkurl = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
    if (strpos($check, "?data=")!==false){ 
     } 
    else { 
     header("Location: index.php");; 
    } 

我认为这会工作,并一直处于这一段时间不能似乎看到了一个问题,但我仍然在学习......

+1

您正在检查名为'$ check',当你应该检查'$ checkurl' – Cyclonecode

+0

:(感谢的是固定的,不确定的变量,如何做IM它呢?再次感谢:) –

+1

我仍然会检查'$ _GET'数组的内容。 – Cyclonecode

回答

3

您需要使用$ _GET

例如

if (!isset($_GET["data"])) { 
    header("Location: index.php"); 
} 

PHP Manual $_GET

+1

谢谢:)我学到的东西新的链接帮了很多 –

1

你试过

if(isset($_GET['data'])) 
{ 
} 
else 
{ 
header("Location: index.php"); 
} 

这样,你只是检查是否有你的URL“数据”

+0

thx为您的答案 –

1

你可以使用这个,因为你也叫做$_GET请求寻找一个查询字符串:

if ($_GET['data'] != 'something') { 
    header('Location: http://test.com'); 
    exit(); 
} 

而且,如果你只是要检查它们是否包含?data=

if (!isset($_GET['data'])) { 
    header('Location: http://test.com'); 
    exit(); 
} 
+0

感谢您的回答:) –

+0

不客气。 – Anonymous