For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > April 2005 > Can php emulate internet explorer browser requests ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Can php emulate internet explorer browser requests ?
Captain

2005-04-26, 3:58 pm

I'm looking to post data (GET) to a site using a php script - commands
like fopen() file_content_gets won't retrieve the data. I assume this
is because the server is expecting the request to come from a browser.

What do I need to do to make sure the request appears to be coming
form a browser, and what would be the best way of posting the data ?
cURL pear fsockopen ? Do I need to recreate the headers that are sent
via IE6 to spoof the server ? Also I think the site may use browser
session cookies and the login page is via https.

If it's too hard or impossible for php I guess I'll have to port my
code over to VB .Net as I assume that program uses the IE libraries
anyway ?
Colin McKinnon

2005-04-26, 3:58 pm

Captain wrote:

> I'm looking to post data (GET) to a site using a php script - commands
> like fopen() file_content_gets won't retrieve the data. I assume this
> is because the server is expecting the request to come from a browser.
>


Tricky.

You should get *something*. The PHP installation may be cobbled if it's not
on a dedicated machine.

The standard system can't cope with cookies, redirects and javascript.
Snoopy (available at sourceforge) can do a lot (but IIRC not javascript)

HTH

C.
Aidan

2005-04-26, 3:58 pm

Captain wrote:

>I'm looking to post data (GET) to a site using a php script - commands
>like fopen() file_content_gets won't retrieve the data. I assume this
>is because the server is expecting the request to come from a browser.
>
>What do I need to do to make sure the request appears to be coming
>form a browser, and what would be the best way of posting the data ?
>cURL pear fsockopen ? Do I need to recreate the headers that are sent
>via IE6 to spoof the server ? Also I think the site may use browser
>session cookies and the login page is via https.
>
>If it's too hard or impossible for php I guess I'll have to port my
>code over to VB .Net as I assume that program uses the IE libraries
>anyway ?
>
>


http://pear.php.net/manual/en/packa...http-client.php
Hannes Dorbath

2005-04-26, 3:58 pm

<?php
ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');

echo file_get_contents('http://google.com/');

?>

it's that easy.

On 26.04.2005 14:38, Captain wrote:
> I'm looking to post data (GET) to a site using a php script - commands
> like fopen() file_content_gets won't retrieve the data. I assume this
> is because the server is expecting the request to come from a browser.
>
> What do I need to do to make sure the request appears to be coming
> form a browser, and what would be the best way of posting the data ?
> cURL pear fsockopen ? Do I need to recreate the headers that are sent
> via IE6 to spoof the server ? Also I think the site may use browser
> session cookies and the login page is via https.
>
> If it's too hard or impossible for php I guess I'll have to port my
> code over to VB .Net as I assume that program uses the IE libraries
> anyway ?

Captain

2005-04-27, 8:56 am

If only it was that easy Hannes :)

The is is the url of one the the pages

http://www.betfair.com/betting/Bets....do?=1062510579

Compare the response from a browser requesting that page and the
file_contents_gets or fopen requests. I think I'll have to check out
the pear scripts as none of the curl ones I tried seemed to work
either

Hannes Dorbath <light@theendofthetunnel.de> wrote in message news:<426e502e$0$24316$8fe63b2a@news.disputo.net>...
> <?php
> ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
>
> echo file_get_contents('http://google.com/');
>
> ?>
>
> it's that easy.
>

Hannes Dorbath

2005-04-27, 8:56 am

that page doesn't work for me even in IE. there is some timeout msg in
the js..

however, it's easy anyway. grab

http://www.blunck.info/iehttpheaders.html

surf that page, take the requerst header, use

fwrite(fsockopen('that.strange.host', 80), $headers);

in case of https use fsockopen('ssl://that.strange.host', 443);

done.

On 27.04.2005 10:43, Captain wrote:[color=darkred]
> If only it was that easy Hannes :)
>
> The is is the url of one the the pages
>
> http://www.betfair.com/betting/Bets....do?=1062510579
>
> Compare the response from a browser requesting that page and the
> file_contents_gets or fopen requests. I think I'll have to check out
> the pear scripts as none of the curl ones I tried seemed to work
> either
>
> Hannes Dorbath <light@theendofthetunnel.de> wrote in message news:<426e502e$0$24316$8fe63b2a@news.disputo.net>...
>
NC

2005-04-27, 3:57 pm

Captain wrote:
>
> I'm looking to post data (GET) to a site using a php script -
> commands like fopen() file_content_gets won't retrieve the data.
> I assume this is because the server is expecting the request
> to come from a browser.


Assumptions won't do. Unless you know what the problem is, you
can't fix it. You need to look at HTTP headers that are being
exchanged between the browser and the server. It is possible
the server sends cookies and expects the client to have them.

> What do I need to do to make sure the request appears to be
> coming form a browser, and what would be the best way of
> posting the data ? cURL pear fsockopen ?


I have worked successfully with both fsockopen() and cURL.

> If it's too hard or impossible for php I guess I'll have to
> port my code over to VB .Net as I assume that program uses
> the IE libraries anyway ?


Since at this point you don't know what your problem is,
switching to another programming language is premature.

Cheers,
NC

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com