【问题标题】:Php global $_GET variablePHP 全局 $_GET 变量
【发布时间】:2019-11-30 02:08:49
【问题描述】:

我有两个文件。一种是header.php 和index.php。我不明白 $_GET['a'] 数据是如何从 header.php 文件传递​​到路由系统的 index.php 的。

我已经尝试找到 $_GET['a'] 从 header.php 到 index.php 的传递方法

图片是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");
}

我希望知道 $_GET['a'] 是如何从 header.php 传递到 index.php

【问题讨论】:

  • 没有任何东西从header.php 传递到index.php$_GET(如 $_SESSION 和 $COOKIE)在全球范围内可用。
  • $_GETsuperglobal。这意味着它在整个脚本的所有范围内都可用。
  • 从屏幕截图看来,您正在将一些基本 URL ($settings[url]) 与链接关键字 testimonialsaffiliate 等组合在一起。所以可能涉及到一些 URL 重写 (. htaccess),它将那些传入的请求从/foo重写为somescript.php?a=foo
  • 那么 $_GET['a'] 的值是多少???并且这个值被插入到 $_GET['a']?? @kerbholz
  • $_GET['a'] 是一个 URL 参数。 php.net/manual/en/reserved.variables.get.php。在您的 URL 中设置,或者在 protect() 函数中的某个位置设置。或者,正如@misorude 所说,在服务器重写中

标签: php


【解决方案1】:

$_GET 查询包含在 URL 中传递给脚本的 keys/values 数组。

如果您有以下网址:

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

数组 'a' => 字符串'登录' (长度=5)

$_GET 不是只读的,如果需要,您还可以从 PHP 代码中设置一些值:

您可以在header.php 中将数据传递给$_GET $_GET['a'] = 'register'; 但这似乎不是一个好的做法,因为$_GET 应该包含来自客户端请求的 URL 的数据。

在 header.php 文件中你需要更改 url <a href="<?= $_GET['a'] ?>">Link</a>

Source

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 2012-03-30
    相关资源
    最近更新 更多