简体   繁体   English

PHP全局$ _GET变量

[英]Php global $_GET variable

I have two files. 我有两个文件。 one is header.php and index.php. 一个是header.php和index.php。 I didn't understand how $_GET['a'] data is passing from header.php file to index.php for the routing system. 我不明白$_GET['a']数据如何从header.php文件传递到路由系统的index.php

I have tried finding $_GET['a'] passing method from header.php to index.php 我试图找到$_GET['a']从header.php传递到index.php的方法

Image is a portion of the header.php file 图像是header.php文件的一部分 在此处输入图片说明

  /*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 我希望知道如何$ _GET ['a']从header.php传递到index.php

$_GET query contains the keys/values array that are passed to your script in the URL. $_GET查询包含在URL中传递给脚本的keys/values数组。

If you have the following URL: 如果您具有以下URL:

http://www.example.com/test.php?a=login Then $_GET will contain : http://www.example.com/test.php?a=login然后$_GET将包含:

array 'a' => string 'login' (length=5) 数组'a'=>字符串'login'(长度= 5)

$_GET is not read-only, you could also set some values from your PHP code, if needed : $_GET不是只读的,如果需要,您还可以从PHP代码中设置一些值:

You can pass data to $_GET in your header.php $_GET['a'] = 'register'; 您可以将数据传递到标头中的$_GET 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. 但这似乎不是一个好习惯,因为$_GET应该包含客户端请求的URL中的数据。

In header.php file you need change urls <a href="<?= $_GET['a'] ?>">Link</a> 在header.php文件中,您需要更改URL <a href="<?= $_GET['a'] ?>">Link</a>

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM