Andy
Andy

Reputation: 3692

Call webpage in the background with PHP

I am trying to write a simple PHP script to retrieve some images from a server - there are four in total. However, everytime I get a new image I need to call a webpage before, i.e http://example.com/Set.cgi?Image=1

I have no control over what is on the server - I just need to work around it. I have read that it is possible using cURL but I'm not sure if my shared host (JustHost) supports it...

Upvotes: 2

Views: 6065

Answers (2)

varuog
varuog

Reputation: 3081

1)even you can use http://php.net/dom to get the web page and fetch it using DOM. but still it needs to enable "allow_url_fopen" directive open.

2) you can use var_dump(ini_get("allow_url_fopen")) to see it is enable or not. you may have permission to put directory based php.ini on your shared host. in this case you can make it enable.

3) you can check using phpinfo() that curl is enabled or not

4) you can use sockets ti simulate curl using fsockopen.

Upvotes: 2

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46768

You can use Curl in the following manner. The following code is from an example on that page.

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://example.com/Set.cgi?Image=1");
curl_setopt($ch, CURLOPT_HEADER, false);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

Upvotes: 4

Related Questions