在 PHP 中从查询字符串获取数据

发布于 2024-10-13 01:56:24 字数 340 浏览 9 评论 0原文

我不知道如何从 PHP 中的 querystring 获取数据。

我想从 access_token 检索数据。

http://www.mygridview.com/sephora/index.php?mod=config#access_token=170791786296375|983b6aefceafdb1cf2d5a122-100001848355029|Hc8qGl6xgpXlmhOWQrLv910on_8&expires_in=0

我该怎么办PHP 中的这个?

I don't know how to get data from the querystring in PHP.

I'd like to retrieve the data from the access_token.

http://www.mygridview.com/sephora/index.php?mod=config#access_token=170791786296375|983b6aefceafdb1cf2d5a122-100001848355029|Hc8qGl6xgpXlmhOWQrLv910on_8&expires_in=0

How do I do this in PHP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧梦荧光笔 2024-10-20 01:56:24

URL 的锚点部分永远不会发送到服务器,因此如果您尝试从当前 URL 加载此信息,该信息将不存在。

就服务器而言,浏览器加载的 URL 是 http://www.mygridview.com/sephora/index.php?mod=config

这是可能的(甚至可能)某些 javascript 使用锚点中的​​信息来恢复使用 AJAX 更改页面后的状态。在这种情况下,您需要研究 Javascript 才能将锚点信息发送到服务器

The anchor part of a URL never gets sent to the server, so if you are trying to load this information from the current URL it won't be there.

As far as the server is concerned, the URL which is loaded by the browser is http://www.mygridview.com/sephora/index.php?mod=config

It's possible (maybe even likely) that some javascript is using the information in the anchor to restore the state of the page after it was altered using AJAX. In that case, it's the Javascript you'll need to look into to get that anchor information sent to the server

千鲤 2024-10-20 01:56:24

签出 http://www.routesjs.com,您应该能够获取值并使用 ajax 发送出去。

Checkout http://www.routesjs.com, you should be able to get the values and send it off with ajax.

泛滥成性 2024-10-20 01:56:24

您获取 url,然后对 url 应用解析函数。
例如::

$url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));

Output::
Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)

这个片段是您的要求。如果我是对的,那么尝试一下就成功了。 :)
感谢

您获取当前 URL::

function getInstance($uri = 'SERVER')
    {

            if ($uri == 'SERVER')
            {
                if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
                    $https = 's://';
                } else {
                    $https = '://';
                }

                if (!empty ($_SERVER['PHP_SELF']) && !empty ($_SERVER['REQUEST_URI'])) {
                    $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

                    if (strlen($_SERVER['QUERY_STRING']) && strpos($_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING']) === false) {
                        $theURI .= '?'.$_SERVER['QUERY_STRING'];
                    }
                }
                 else
                 {
                    $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
                    if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
                        $theURI .= '?' . $_SERVER['QUERY_STRING'];
                    }
                }

                $theURI = urldecode($theURI);
                $theURI = str_replace('"', '"',$theURI);
                $theURI = str_replace('<', '<',$theURI);
                $theURI = str_replace('>', '>',$theURI);
                $theURI = preg_replace('/eval\((.*)\)/', '', $theURI);
                $theURI = preg_replace('/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', $theURI);

        }
        echo (string)$theURI;
    }

You get url and then apply parse function on url.
eg::

$url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));

Output::
Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)

this fragment is your requirement. If i'm right then try this n got success. :)
Thanks

for get current URL::

function getInstance($uri = 'SERVER')
    {

            if ($uri == 'SERVER')
            {
                if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
                    $https = 's://';
                } else {
                    $https = '://';
                }

                if (!empty ($_SERVER['PHP_SELF']) && !empty ($_SERVER['REQUEST_URI'])) {
                    $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

                    if (strlen($_SERVER['QUERY_STRING']) && strpos($_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING']) === false) {
                        $theURI .= '?'.$_SERVER['QUERY_STRING'];
                    }
                }
                 else
                 {
                    $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
                    if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
                        $theURI .= '?' . $_SERVER['QUERY_STRING'];
                    }
                }

                $theURI = urldecode($theURI);
                $theURI = str_replace('"', '"',$theURI);
                $theURI = str_replace('<', '<',$theURI);
                $theURI = str_replace('>', '>',$theURI);
                $theURI = preg_replace('/eval\((.*)\)/', '', $theURI);
                $theURI = preg_replace('/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', $theURI);

        }
        echo (string)$theURI;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文