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

Zain Aftab
  • 703
  • 7
  • 21
  • Nothing gets passed from `header.php` to `index.php`. `$_GET` (like $_SESSION and $COOKIE) are globally available. – brombeer Jul 22 '19 at 06:34
  • `$_GET` is a [superglobal](https://www.php.net/manual/en/language.variables.superglobals.php). Which means it is available in all scopes throughout a script. – KIKO Software Jul 22 '19 at 06: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` – misorude Jul 22 '19 at 06:35
  • Then what is the value of $_GET['a'] ??? and where this value is inserted into $_GET['a']?? @kerbholz – Mostafijur Rahman Jul 22 '19 at 06:39
  • `$_GET['a']` is a URL parameter. https://www.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 – brombeer Jul 22 '19 at 06:41
  • @misorude you got the point.Kindly tell me what is the location htaccess file?? this url rewriting method works only in live server not loclhost??? – Mostafijur Rahman Jul 22 '19 at 06:42
  • URL rewriting in Apache can be configured in multiple places, but most likely you are looking for an .htaccess file at the domain root level of the project. – misorude Jul 22 '19 at 06:45

1 Answers1

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

Farhod Nematov
  • 470
  • 2
  • 8