drti52047 2013-04-19 13:10
浏览 231

PHP - 从iframe获取父窗口的URL参数

So far, I can place the first URL parameter and its value into variables - from child (iframed) page.

E.g http://google.com/?x=123 I can get x=123

I have used this code for the page (child) that is iframed.

<?php
   //Getting the parent window parameters
    $getURLVar = str_replace("?","",strrchr($_SERVER['HTTP_REFERER'],"?"));
    $getURLVar = str_replace("&","=",$getURLVar);
    $getURLVar = str_getcsv($getURLVar,"=");
    $i=0;
    foreach ($getURLVar as $value)
      {
        if ($i % 4)
            $value1[$i]=$value;

        else
            $value2[$i]=$value;


        $i++;
      } 
   // $getURLVar =array_combine($value2,$value1);


    //print_r($getURLVar);

list($v1, $v2) = $getURLVar;
 echo "$v1";

echo "$v2";


    ?>

Question: What if I had more than 1 parameter? E.g http://google.com/&x=234&results=10

Please help me amend the above to support more than 1 parameter.

Thank you

  • 写回答

1条回答 默认 最新

  • doru52911 2013-04-19 13:13
    关注

    Use http://www.php.net/manual/function.parse-str.php and http://www.php.net/manual/function.parse-url.php to parse the HTTP_REFERER.

    //edit:

    $referer = 'http://www.google.de/?q=test&foo=bar&blub=bla';
    
    $url = parse_url($referer);
    
    print_r($url);
    
    if(!empty($url['query'])){
        parse_str($url['query'], $query_params);
        print_r($query_params);
    }
    

    Maybe you should read something more about the basics...

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序