Mostafijur Rahman
Mostafijur Rahman

Reputation: 23

Php global $_GET variable

I have two files. one is header.php and index.php. I didn't understand how $_GET['a'] data is passing from header.php file to index.php for the routing system.

I have tried finding $_GET['a'] passing method from header.php to index.php

Image is a portion of the header.php file enter image description here

  /*index.php*/

include("sources/header.php");
$a = protect($_GET['a']);
switch ($a) {
    case "account": include("sources/account.php"); break;
    case "login": include("sources/login.php"); break;
    case "register": include("sources/register.php"); break;
    case "track": include("sources/track.php"); break;
    case "testimonials": include("sources/testimonials.php"); break;
    case "affiliate": include("sources/affiliate.php"); break;
    case "contact": include("sources/contact.php"); break;
    case "about": include("sources/about.php"); break;
    case "faq": include("sources/faq.php"); break;
    case "page": include("sources/page.php"); break;
    case "exchange": include("sources/exchange.php"); break;
    case "search": include("sources/search.php"); break;
    case "password": include("sources/password.php"); break;
    case "email-verify": include("sources/email-verify.php"); break;
    case "logout":
        unset($_SESSION['bit_uid']);
        unset($_COOKIE['bitexchanger_uid']);
        setcookie("bitexchanger_uid", "", time() - (86400 * 30), '/'); //         86400 = 1 day
        session_unset();
        session_destroy();
        header("Location: $settings[url]");
        break;
    default: include("sources/homepage.php");
}

I expect to know how $_GET['a'] is passing from header.php to index.php

Upvotes: 0

Views: 269

Answers (1)

Farhod Nematov
Farhod Nematov

Reputation: 385

$_GET query contains the keys/values array that are passed to your script in the URL.

If you have the following URL:

http://www.example.com/test.php?a=login Then $_GET will contain :

array 'a' => string 'login' (length=5)

$_GET is not read-only, you could also set some values from your PHP code, if needed :

You can pass data to $_GET in your header.php $_GET['a'] = 'register'; But this doesn't seem like good practice, as $_GET is supposed to contain data from the URL requested by the client.

In header.php file you need change urls <a href="<?= $_GET['a'] ?>">Link</a>

Source

Upvotes: 2

Related Questions