How do I use $ _GET?

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

<?php
session_start();
if(isset($_SESSION['logged_in'])){
    $id = $_SESSION['id'];
    header("Location: start.php?id=$id");
    exit();
}

if(isset($_POST['submit'])){

    $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
                        exit();

      

start.php will simply be:

<?php
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.

+3


source to share


2 answers


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

http://example.org/index.php?foo=bar&baz=1

      

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.

+5


source


$_GET

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.

+2


source







All Articles