iframe中父窗口的GET变量问题

时间:2012-05-23 17:12:27

标签: php iframe get

我有一个父窗口,其中包含以下网址:http://example.com?val=test

在该页面的iframe中,我需要val附加到链接。

目前我在iframe中执行此操作:

<?php
$val = $_GET['val'];
?>
<a href ="http://example.com/link.html?val=<?php echo $val ?>">Link</a>

输出包含额外的/',如下所示:
http://example.com/link.html?val=\'test\'

有没有办法正确地做到这一点?

2 个答案:

答案 0 :(得分:2)

试试这个:

$val = trim(stripslashes($_GET['val']),"'");

答案 1 :(得分:1)

您正在体验PHP的魔术引语的痛苦。您应该关闭它们(首选)或剥去斜线。有关详细信息,请参阅http://php.net/manual/en/security.magicquotes.php

要完全禁用它们,请将它放在php.ini文件中

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off

要从$ _GET变量中删除它们,请使用stripslashes。

<?php
// from http://www.php.net/manual/en/security.magicquotes.disabling.php#91585
if (get_magic_quotes_gpc()) {
    function stripslashes_gpc(&$value)
    {
        $value = stripslashes($value);
    }
    array_walk_recursive($_GET, 'stripslashes_gpc');
    array_walk_recursive($_POST, 'stripslashes_gpc');
    array_walk_recursive($_COOKIE, 'stripslashes_gpc');
    array_walk_recursive($_REQUEST, 'stripslashes_gpc');
}
?>