我遇到过一种情况,我需要将$_SESSION变量从一个域传递到另一个域的iFrame页面.我花了最后16天尝试各种方法无济于事.我认为唯一合乎逻辑的方法是在url中编码调用iFrame的变量并在iFrame页面中解码它们.我不知道该怎么做,我正在寻找我能找到的任何样品,帮助等.
感谢您的任何建议.
这是我想要做的一个例子……
例:
<!-- Note only using hidden as I didn't want to build the form at test phase--> <form name="test" method="post" action="iframe_test.PHP"> <input type="submit" name="Submit" /> <input type="hidden" name="fName" value="abc" /> <input type="hidden" name="lName" value="def" /> <input type="hidden" name="address1" value="ghi" /> <input type="hidden" name="address2" value="jkl" /> <input type="hidden" name="country" value="mno" /> <input type="hidden" name="postal_code" value="pqr" /> <input type="hidden" name="city" value="stu" /> <input type="hidden" name="retUrl" value="vwx"> <input type="hidden" name="decUrl" value="yz">
所以,从这里我打击iframe_test.PHP并执行以下操作:
PHP代码:
功能StripSpecChar($val){
return(preg_replace(‘/ [^ a-zA-Z0-9“” – .@:/ _] /’,”,$val));
}
foreach ($_POST as $key => $val) { $_SESSION[$key] = StripSpecChar($val); }
我得到一个如下所示的会话数组:
码:
Array ( [fName] => abc [lName] => def [address1] => ghi [address2] => jkl [country] => mno [postal_code] => pqr [city] => stu [retUrl] => vwx [decUrl] => yz )
到目前为止仍然很好……打电话给iFrame
码:
<body> Some page stuff here <div align="center"><span class="style1"><strong>This is the iFrame Page</strong></span> </div> <div align="center"> <iframe src="https://www.other_domain.org/iframe/reserve.PHP" width="500" height="350" frameBorder="0"></iframe> </div> </body>
那我该怎么做……
$_SESSION['fName']['abc']; $_SESSION['lName']['def']; $_SESSION['address1']['ghi']; $_SESSION['address2']['jkl']; $_SESSION['country']['mno']; $_SESSION['postal_code']['pqr']; $_SESSION['city']['stu']; $_SESSION['retUrl']['vwx']; $_SESSION['decUrl']['yz'];
并将其转换为我正在寻找的编码网址?进一步完成后,如何将会话变量恢复为新域iFrame页面上的会话变量…
序列化sessiondata数组并将其作为参数发送,然后反序列化
http://www.php.net/manual/en/function.serialize.php
http://www.php.net/manual/en/function.serialize.php