php 如何在php中调用任何其他网站的url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2446654/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to call url of any other website in php
提问by Beginner
how to call url of any other website in php.
如何在php中调用任何其他网站的url。
回答by OverLex
use curl php library: http://php.net/manual/en/book.curl.php
使用 curl php 库:http: //php.net/manual/en/book.curl.php
direct example: CURL_EXEC:
直接示例:CURL_EXEC:
<?php
// create a new cURL resource
$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);
?>
回答by Andy E
As other's have mentioned, PHP's cURL functions will allow you to perform advanced HTTP requests. You can also use file_get_contentsto access REST APIs:
正如其他人提到的,PHP 的 cURL 函数将允许您执行高级 HTTP 请求。您还可以使用file_get_contents访问 REST API:
$payload = file_get_contents('http://api.someservice.com/SomeMethod?param=value');
Starting with PHP 5 you can also create a stream contextwhich will allow you to change headers or post data to the service.
从 PHP 5 开始,您还可以创建一个流上下文,这将允许您更改标题或将数据发布到服务。
回答by Jamescun
The simplest way would be to use FOpen or one of FOpen's Wrappers.
最简单的方法是使用 FOpen 或 FOpen 的 Wrappers 之一。
$page = file_get_contents("http://www.domain.com/filename");
This does require FOpen which some web hosts disable and some web hosts will allow FOpen, but not allow access to external files. You may want to check where you are going to run the script to see if you have access to External FOpen.
这确实需要 FOpen,某些 Web 主机禁用它,而某些 Web 主机将允许 FOpen,但不允许访问外部文件。您可能需要检查将在哪里运行脚本以查看您是否有权访问外部 FOpen。
回答by Shrayas
If you meant .. to REDIRECTfrom that page to another, the function is really simple
如果你的意思是......从那个页面重定向到另一个页面,这个功能真的很简单
header("Location:www.google.com");

