使用php检查URL以获取信息

I am wanting to check the url of one of my pages if the user has landed correctly

for example if a user visits www.example.com/page.php?data=something

The user will beable to view the page

but if the user visits www.example.com/page.php he gets redirected

This is my current code

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

I thought this would work and been at this for a while cant seem to see a problem but i am still learning...

You need to use $_GET

For example

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

PHP Manual $_GET

Have you tried

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

This way you just check if there is a "data" on your URL

You can just use this since you are looking for a query string aka a $_GET request:

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

Also, if you just want to check if they included ?data=:

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