Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call url of any other website in php [closed]

Tags:

php

how to call url of any other website in php.

like image 752
Beginner Avatar asked Mar 15 '10 11:03

Beginner


2 Answers

use curl php library: http://php.net/manual/en/book.curl.php

direct example: 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); ?> 
like image 103
OverLex Avatar answered Oct 02 '22 13:10

OverLex


As other's have mentioned, PHP's cURL functions will allow you to perform advanced HTTP requests. You can also use file_get_contents to access REST APIs:

$payload = file_get_contents('http://api.someservice.com/SomeMethod?param=value'); 

Starting with PHP 5 you can also create a stream context which will allow you to change headers or post data to the service.

like image 26
Andy E Avatar answered Oct 02 '22 13:10

Andy E