【问题标题】:To convert a data obtained through URL to post variables将通过 URL 获取的数据转换为 post 变量
【发布时间】:2011-09-05 18:36:40
【问题描述】:

我需要阅读使用 POST 操作类型进行提交的表单的结果。那么,我是否可以将通过 GET 变量获得的变量转换为 POST,然后我可以使用 file_get_contents() 简单地读取内容。

如果可能,请帮助我使用此方法或通过其他方法获取数据。

【问题讨论】:

    标签: php html post


    【解决方案1】:

    file_get_contents可以通过stream_context_create来执行POST请求:

    $options = array('http'=>array(
            'method'=>'POST',
            'header'=>'Content-type: application/x-www-form-urlencoded',
            'content'=>'var1=a&var2=b'
        )
    );
    
    echo file_get_contents('http://somesite.com/someform/', false, stream_context_create($options));
    

    【讨论】:

    • 但是我有这个问题。我无法为传递的参数设置变量值 a、b。我正在使用此代码使用此代码从 url 中提取 regno(我的参数):-
    • var p = document.location.href; var p_1 = p.split("="); var req = p_1[1];
    【解决方案2】:

    从表单传递到 PHP 的所有参数都将填充到超全局 $_POST

    如果不确定参数是通过 GET 还是 POST 给出,可以使用超全局 $_REQUEST

    【讨论】:

    • + $_REQUEST 包含 $_COOKIE 的内容
    • var p = document.location.href; var p_1 = p.split("="); var req = p_1[1];
    猜你喜欢
    • 2020-11-04
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 2019-06-29
    • 1970-01-01
    • 2012-01-02
    • 2016-01-01
    • 2019-11-21
    相关资源
    最近更新 更多