嗨,我是新手,想知道一些header('location:mysit.php');的替代功能
我在一个场景中发送请求,如下所示:
header('Location: http://localhost/(some external site).php'&?var='test')类似这样,但我想要做的是,我想要将变量的值发送到外部站点,但实际上我不希望该页面弹出。
我的意思是,变量应该被发送到一些外部站点/页面,但在屏幕上,我希望被重定向到我的登录页面。但似乎我不知道其他选择,请指导我。谢谢。
发布于 2011-11-21 19:37:57
您正在搜索PHP cUrl
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);发布于 2011-11-21 19:37:05
将location头设置为您实际想要将浏览器重定向到的位置,并使用类似cURL的内容向远程站点发出HTTP请求。
发布于 2011-11-21 19:44:28
通常的方法是通过cURL发送这些参数,解析返回值并根据需要使用它们。
通过使用cURL,您可以将POST和GET变量传递给任何URL。如下所示:
$ch = curl_init('http://example.org/?aVariable=theValue');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);现在,在$result中,您有来自传递给curl_init()的URL的响应。
如果你需要post数据,代码需要更多:
$ch = curl_init('http://example.org/page_to_post_to.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'variable1=value1&variable2=value2');
$result = curl_exec($ch);
curl_close($ch);同样,POST请求的结果将保存到$result。
https://stackoverflow.com/questions/8211113
复制相似问题