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.. Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/ 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 Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261304 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 Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261348 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'; Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261351 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 Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261352 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); Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261363 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? Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261365 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; } ?> Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261525 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? Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261716 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>'); } Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261719 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 Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-261741 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")); ?> Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-262050 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? Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-262660 Share on other sites More sharing options...
acidglitter Posted May 29, 2007 Author Share Posted May 29, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-263610 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. Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-263613 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. Link to comment https://forums.phpfreaks.com/topic/52910-php-sockets/#findComment-265168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.