2011-01-21 124 views
0

我不知道如何从PHP中的querystring获取数据。从PHP中的查询字符串获取数据

我想从access_token检索数据。

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

我如何在PHP这样做呢?

+0

正确答案完全取决于您打算如何将该URL提供给PHP。请澄清。 [另外,这至少是一式四份](http://stackoverflow.com/search?q=fragment+url+php),所以你应该指出你尝试过哪些方法,以及为什么它仍然不起作用。 – Gordon 2011-01-21 12:02:22

+0

[PHP&Hash/Fragment部分的URL]的可能重复(http://stackoverflow.com/questions/1162008/php-hash-fragment-portion-of-url) – Gordon 2011-01-21 12:03:16

+0

您试图解析哪个URL?当前页面的URL,还是从其他地方获得的? – Gareth 2011-01-21 12:10:12

回答

1

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

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

这是可能的(甚至可能),一些JavaScript是使用锚信息来恢复页面的状态使用AJAX进行修改后。在这种情况下,您需要查看Javascript以获取发送到服务器的锚点信息。

0

您获取了url,然后在url上应用分析函数。 例如:

$url = 'http://username:[email protected]/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 
) 

这个片段是你的要求。如果我是对的,那么试试这个n取得成功。 :) 感谢

用于获取当前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('<', '&lt;',$theURI); 
       $theURI = str_replace('>', '&gt;',$theURI); 
       $theURI = preg_replace('/eval\((.*)\)/', '', $theURI); 
       $theURI = preg_replace('/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', $theURI); 

     } 
     echo (string)$theURI; 
    } 
相关问题