简体   繁体   中英

Issue with GET variables of parent window in iframe

I have a parent window with the URL: http://example.com?val=test

In the iframe of that page, I need to get val to append to a link.

Currently I'm doing this in the iframe:

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

The output contains extra / and ' like this:
http://example.com/link.html?val=\\'test\\'

Is there a way to do this properly?

尝试这个:

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

You are experiencing the pain of PHP's magic quotes. You should either turn them off (prefered) or strip the slashes. See http://php.net/manual/en/security.magicquotes.php for details.

To disable them completely, put this in your php.ini file

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

To remove them from $_GET variables, use 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');
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM