Page 1 of 1

how to connect to a remote ip?

Posted: Tue Sep 13, 2005 1:42 am
by saumya
how can i connect to a remote ip such as http://www.google.com
What i want is open the site and take all the contents from that site and show it in my page.

Posted: Tue Sep 13, 2005 2:19 am
by 127.0.0.1
There are loads of ways to achieve this.

I preffer to use curl when "taking content that is not mines".

with curl it makes it easy to fake HTTP referrer and HTTP agent.

Example

Code: Select all

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.google.com/search?q=php");
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.2a)");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
$GoogleContent = curl_exec ($ch);
curl_close($ch);
I hope I got the code right this time and it has came out ok. I am knew to this forum.

There are a lot more features to curl its worth checking out.

http://uk.php.net/curl

As for working with the data it depends what part you are wanting to strip out. 2 Options you can explode into an array and work with the data there or use regular expressions. Regular expressions is probably your best bet.

Oh one last thing if you use curl make sure you set the useragent to something otherwise it will default to curl and youll get detected very easily.

Posted: Tue Sep 13, 2005 3:32 am
by saumya
thank you.