pouncer Posted April 1, 2007 Share Posted April 1, 2007 Hey guys What I'm wanting to do is connect to http://onelook.com on port 80 and submit a word to lookup. I'm not sure how I go about setting the socket up, and what to send to the socket etc. Any ideas guys? Link to comment https://forums.phpfreaks.com/topic/45166-using-php-sockets/ Share on other sites More sharing options...
pouncer Posted April 1, 2007 Author Share Posted April 1, 2007 ok guys, I had a go at this but no luck! <?php $host = "www.onelook.com"; $fp = fsockopen($host, 80, $errno, $errdesc) or die("Connection to $host failed"); $request = "GET /w=cat&ls=a HTTP/1.0\r\n"; $request .= "Host: $host\r\n"; $request .= "Accept-Language: en-us\r\n"; $request .= "Accept-Encoding: gzip, deflatez\r\n"; $request .= "Accept: */*\r\n\r\n"; fputs($fp, $request); while(!feof($fp)){ $page[] = fgets($fp, 1024); } fclose($fp); echo "The server returned ".(count($page)). " Lines"; for($i=0; $i<count($page); $i++){ echo $page[$i]; } ?> Try to conect for e.g: http://www.onelook.com/?w=cat&ls=a It just keeps giving me a 302 error. What I'm actually looking to do is to check on the right of the page where it says Quick definitions (cat) noun: feline mammal usually having thick soft fur and being unable to roar; domestic cats; wildcats It it finds that the word is a noun and or an adjective, I just want it to return/halt and echo "Word is a noun" etc can anyone help? Link to comment https://forums.phpfreaks.com/topic/45166-using-php-sockets/#findComment-219307 Share on other sites More sharing options...
fert Posted April 1, 2007 Share Posted April 1, 2007 why don't you use curl? Link to comment https://forums.phpfreaks.com/topic/45166-using-php-sockets/#findComment-219308 Share on other sites More sharing options...
pouncer Posted April 1, 2007 Author Share Posted April 1, 2007 i don't think my host has it! anyone know whats wrong with my code? Link to comment https://forums.phpfreaks.com/topic/45166-using-php-sockets/#findComment-219319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.