acidglitter Posted May 25, 2007 Share Posted May 25, 2007 So I want to make a page on my site, that can (on its own) go to another site I tell it to go to and come back with a certain HTML code. How could I do that?? I looked up some things about php sockets and parsers but it confused me.. Quote Link to comment Share on other sites More sharing options...
Glyde Posted May 25, 2007 Share Posted May 25, 2007 Here's a simple example that'll pull information off of a web page <?php function getHTML($website) { $url = parse_url($website); $handle = fsockopen($url['host'], 80); $request = "GET {$url['path']} HTTP/1.1\r\n"; $request .= "Host: {$url['host']}\r\n\r\n"; fputs($handle, $request, strlen($request)); $response = ""; while (!feof($handle)) $response .= fgets($handle, 1024); print $response; } ?> That should work, then you can manipulate it as you feel needed Quote Link to comment Share on other sites More sharing options...
acidglitter Posted May 25, 2007 Author Share Posted May 25, 2007 Thanks I'm not really sure how to use it though. I put getHTML("http://vanillaeyeliner.com"); but I got this error Bad Request Your browser sent a request that this server could not understand. Invalid URI in request GET HTTP/1.1 Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Apache/1.3.37 Server at x.geminiserver.com Port 80 Quote Link to comment Share on other sites More sharing options...
rhyspaterson Posted May 25, 2007 Share Posted May 25, 2007 You need to give the variable something to work with. $website = 'http://vanillaeyeliner.com'; Quote Link to comment Share on other sites More sharing options...
acidglitter Posted May 25, 2007 Author Share Posted May 25, 2007 You need to give the variable something to work with. $website = 'http://vanillaeyeliner.com'; I tried that and it still had the same error message Quote Link to comment Share on other sites More sharing options...
rhyspaterson Posted May 25, 2007 Share Posted May 25, 2007 You must call the function and give it the variable. <?php function getHTML($website) { $url = parse_url($website); $handle = fsockopen($url['host'], 80); $request = "GET {$url['path']} HTTP/1.1\r\n"; $request .= "Host: {$url['host']}\r\n\r\n"; fputs($handle, $request, strlen($request)); $response = ""; while (!feof($handle)) $response .= fgets($handle, 1024); print $response; } ?> $website = 'http://www.google.com' getHTML($website); Quote Link to comment Share on other sites More sharing options...
acidglitter Posted May 25, 2007 Author Share Posted May 25, 2007 Okay there aren't any error messages now, but the page is blank.. How do I show it? Quote Link to comment Share on other sites More sharing options...
Glyde Posted May 25, 2007 Share Posted May 25, 2007 I forgot to add something in the code. Try it now. <?php function getHTML($website) { $url = parse_url($website $url['path'] = substr($url['path'], 0, 1) == "/" ? $url['path'] : "/" . $url['path']; $handle = fsockopen($url['host'], 80); $request = "GET {$url['path']} HTTP/1.1\r\n"; $request .= "Host: {$url['host']}\r\n\r\n"; fputs($handle, $request, strlen($request)); $response = ""; while (!feof($handle)) $response .= fgets($handle, 1024); print $response; } ?> Quote Link to comment Share on other sites More sharing options...
acidglitter Posted May 25, 2007 Author Share Posted May 25, 2007 Thats awesome. Thanks ;D So my code looks like this: <?php function getHTML($website) { $url = parse_url($website); $url['path'] = substr($url['path'], 0, 1) == "/" ? $url['path'] : "/" . $url['path']; $handle = fsockopen($url['host'], 80); $request = "GET {$url['path']} HTTP/1.1\r\n"; $request .= "Host: {$url['host']}\r\n\r\n"; fputs($handle, $request, strlen($request)); $response = ""; while (!feof($handle)) $response .= fgets($handle, 1024); print $response; } $website = 'http://www.google.com'; getHTML($website); ?> How should I change it so it still gets the entire page, but then the only thing it displays is the Google logo image? Quote Link to comment Share on other sites More sharing options...
taith Posted May 25, 2007 Share Posted May 25, 2007 function getHTML($website) { $url = parse_url($website); $url['path'] = substr($url['path'], 0, 1) == "/" ? $url['path'] : "/" . $url['path']; $handle = fsockopen($url['host'], 80); $request = "GET {$url['path']} HTTP/1.1\r\n"; $request .= "Host: {$url['host']}\r\n\r\n"; fputs($handle, $request, strlen($request)); $response = ""; while (!feof($handle)) $response .= fgets($handle, 1024); print strip_tags($response,'<img>'); } Quote Link to comment Share on other sites More sharing options...
acidglitter Posted May 25, 2007 Author Share Posted May 25, 2007 So it showed this <img alt='' height=1 id=gbari width=1>document.getElementById('gbarc').style.height=(document.getElementById('gbari').height=window.gbar.getPad())+'px';document.getElementById('gbar').innerHTML=window.gbar.getHtml([['w','Web','',1],['i','Images','http://images.google.com/imghp',1],['v','Video','http://video.google.com/',1],['n','News','http://news.google.com/nwshp',1],['l','Maps','http://maps.google.com/maps',1],['m','Gmail','http://mail.google.com/mail',1],['','more','#',3],['b','Blog Search','http://blogsearch.google.com/',2],['j','Blogger','http://www.blogger.com/',2],['p','Books','http://books.google.com/bkshp',2],['c','Calendar','http://www.google.com/calendar',2],['o','Documents','http://docs.google.com/',2],['e','Finance','http://finance.google.com/finance',2],['g','Groups','http://groups.google.com/grphp',2],['z','Labs','http://labs.google.com/',2],['0','Orkut','http://www.orkut.com/',2],['t','Patents','http://www.google.com/ptshp',2],['q','Photos','http://picasaweb.google.com/home',2],['f','Products','http://www.google.com/prdhp',2],['y','Reader','http://www.google.com/reader',2],['s','Scholar','http://scholar.google.com/schhp',2]]);iGoogle | Sign in<img alt="Google" height=110 src="/intl/en_ALL/images/logo.gif" width=276> Advanced Search Preferences Language ToolsAdvertising Programs - Business Solutions - About Google©2007 Google I meant more of how could I get it to get the exact address of the image, like only show this intl/en_ALL/images/logo.gif Quote Link to comment Share on other sites More sharing options...
Glyde Posted May 26, 2007 Share Posted May 26, 2007 <?php function getImages($website) { $url = parse_url($website); $url['path'] = substr($url['path'], 0, 1) == "/" ? $url['path'] : "/" . $url['path']; $handle = fsockopen($url['host'], 80); $request = "GET {$url['path']} HTTP/1.1\r\n"; $request .= "Host: {$url['host']}\r\n\r\n"; fputs($handle, $request, strlen($request)); $response = ""; while (!feof($handle)) $response .= fgets($handle, 1024); $response = strip_tags($response,'<img>'); preg_match_all("@<img[^>]+?src=\"([^\"]+)\"[^>]+?>@is", $response, $matches); return $matches; } print_r(getImages("http://www.google.com")); ?> Quote Link to comment Share on other sites More sharing options...
acidglitter Posted May 27, 2007 Author Share Posted May 27, 2007 Thanks for all the help so far This is probably my last question about it.. If I wanted to see what my myspace inbox looked like, using the original code it would look like this.. <?php function getHTML($website) { $url = parse_url($website); $url['path'] = substr($url['path'], 0, 1) == "/" ? $url['path'] : "/" . $url['path']; $handle = fsockopen($url['host'], 80); $request = "GET {$url['path']} HTTP/1.1\r\n"; $request .= "Host: {$url['host']}\r\n\r\n"; fputs($handle, $request, strlen($request)); $response = ""; while (!feof($handle)) $response .= fgets($handle, 1024); print $response; } $website = 'http://messaging.myspace.com/index.cfm?fuseaction=mail.inbox'; getHTML($website); ?> But the problem is I need to be signed in to see it.. Is there a way I could put my username/password in the socket so it could still get the page html? Quote Link to comment Share on other sites More sharing options...
acidglitter Posted May 29, 2007 Author Share Posted May 29, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
trq Posted May 29, 2007 Share Posted May 29, 2007 This whole process would be much easier using curl. Quote Link to comment Share on other sites More sharing options...
Glyde Posted May 30, 2007 Share Posted May 30, 2007 Yea, it would be, but at first I didn't know he needed to be signed in. Plus, I don't like coding for 3rd party extensions to the public because a lot of people don't have them installed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.