tags:

views:

232

answers:

5

I know that this is a simple question for PHP guys but I don't know the language and just need to do a simple "get" from another web page when my page is hit. i.e. signal the other page that this page has been hit.

EDIT: curl is not available to me.

+5  A: 

If curl wrappers are on (they are per default), you can use:

file_get_contents('http://www.example.org');

Note that this happens synchronous, so before the request has completed, your page won't either. It would be better to log access to a logfile (or database) and export the data occasionally. Alternatively, you could do the request after your page has completed, and output has been sent to the client.

troelskn
I think troelskn means file wrappers and not cURL wrappers, since you do not, necesserly, need cURL to use file_get_contents() with an HTTP protocol.
Gustavo Carreno
@gustavo You're right. I always thought those filewrappers used curl underneath, but it must have been something I made up, 'cause I can't find it in the manual to support it.
troelskn
A: 

You'll probably want to use cURL

Gerald
It's not fair to vote this down for suggesting something that the question didn't rule out before the answer was posted. :(
eyelidlessness
+1  A: 

There's numerous ways... the simplest is file_get_contents('http://...'); Other functions like fopen() also support http: streams.

If you need more control, I'd suggest looking at curl (see curl_init)

Greg
+2  A: 

Beware file_get_contents() and fopen():

If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.

eyelidlessness
+1  A: 

There are a number of ways to send a GET request with PHP. As mentioned above, you can use file_get_contents, fopen or cURL.

You can also use the HTTP extension, the fsockopen() function or streams via fopen.

I'd advise checking out what WordPress has done, as it handles almost all possibilities.

Ryan McCue