繁体   English   中英

如何在PHP中通过URL传递变量

[英]how to pass a variable thru URL in php

嗨,我正在尝试通过URL将值从一个文件传递到另一个文件。

我的方式是: <a href='fund_view.php?idfund="<? echo $row['idfund']; ?>"'>

毕竟我在其他文件中使用了正确的值

$aidi = $_GET['idfund'];

echo 'ID= '.$aidi;`

但是我得到的结果是此格式ID= \\"10\\"

我通过id后的网址看起来像

http://example.com/fund_view.php?idfund="10"

我想要的结果只是ID="10"

在php.ini中关闭magic_quotes ,您应该摆脱那些反斜杠。

更改

<a href='fund_view.php?idfund="<? echo $row['idfund']; ?>"'>

<a href='fund_view.php?idfund=<? echo $row['idfund']; ?>'>

另外请记住,您的代码是非常不安全的...至少在使用它之前将参数强制转换为int:

$aidi = (integer) $_GET['idfund'];

PHP的早期版本(低于5.4)具有疯狂的反直觉功能,称为“魔术引号” ,该功能自动(且无提示)转义所有GET / POST字符串,就像它们将在MySQL查询中使用一样。

反向操作相对简单,当您不知道存在这样的功能时就很头痛。

解决方案1:使用ini_set关闭magic_quotes

有时您将无法使用ini_set(限制性主机提供程序),因此以下是我使用的次佳(可移植)解决方案:

注意: get_magic_quotes_gpc函数页面上提供的函数

<?php
    function stripslashes_deep(&$value)
    {
        $value = is_array($value) ?
                    array_map('stripslashes_deep', $value) :
                    stripslashes($value);

        return $value;
    }

    if (get_magic_quotes_gpc())
    {
        stripslashes_deep($_GET);
        stripslashes_deep($_POST);
    }

?> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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