0

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

7
  • Nothing gets passed from header.php to index.php. $_GET (like $_SESSION and $COOKIE) are globally available. Commented Jul 22, 2019 at 6:34
  • $_GET is a superglobal. Which means it is available in all scopes throughout a script. Commented Jul 22, 2019 at 6:35
  • From the screenshot it looks like you are combining some base URL ($settings[url]) with a link keyword, testimonials, affiliate, etc. So there is probably some URL rewriting involved (.htaccess), that rewrites those incoming requests from /foo to somescript.php?a=foo Commented Jul 22, 2019 at 6:35
  • Then what is the value of $_GET['a'] ??? and where this value is inserted into $_GET['a']?? @kerbholz Commented Jul 22, 2019 at 6:39
  • $_GET['a'] is a URL parameter. php.net/manual/en/reserved.variables.get.php. Set in your URL or maybe somewhere in that protect() function. Or, as @misorude stated, in a server rewrite Commented Jul 22, 2019 at 6:41

1 Answer 1

2

$_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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.