How do I use $ _GET?

I have the following login script where I am using sessions.

    $id = $_SESSION['id'];
    header("Location: start.php?id=$id");


    $x1 = $_POST['x1'];
    $x2 = $_POST['x2'];
$query = $db->query("SELECT * FROM table WHERE x1='".$x1."' AND x2='".$x2."'");
        if($query->num_rows === 1){

            $row = $query->fetch_object();
            $id = $row->id;

                        $_SESSION['logged_in'] = true;
            $_SESSION['id'] = $id;
            header("Location: start.php?id=$id");

                        3more queries


start.php will simply be:

echo $_GET['id'];


I thought that $ _GET ['id'] would be stored on the server to display $ _GET. fetch_object works. I know this because it will display correctly in "id = $ id" in the browser. so someone would be so friendly and could help me. thank.


source to share

2 answers

The superglobal value $ _GET is defined as part of the URL string:


In index.php:

echo $_GET['foo']; // bar
echo $_GET['baz']; // 1


This way, $ _GET is not stored on the server, but passed with every HTTP request, just like $ _POST, but passed in HTTP headers rather than just appended to the end of the URL.




the variables are the ones that are passed through the url, i.e. index.php?foo=bar&baz=qux

( foo

equal bar

, baz

equal qux


These variables are not stored on the server as part of the session, but rather only exist with this request. If you want to store information on the server as part of a session, you should instead use $_SESSION

one that will exist in the current session regardless of the request.



All Articles