Jump to content

Fsockopen help!


legohead6

Recommended Posts

Hi, i am just starting to learn about sockets, and have made a simple code, it works great and the google homepage loads, but no pictures are displayed(red x's) and the links arent displayed, the probelm is its trying to link to my website for the pics(EX pic is at google.com/pic.jpg, its trying to find it at example.com/pic.jpg) how could i fix this? i have to set the headers somehow im assuming, but dont know how! could someone please help me out, i am trying to learn sock stuff so please dont just give me a 1000line code without explaning it...

<?php
fsockopen ("www.google.com", 80);
    fwrite($connection, "GET / HTTP/1.1\r\nHOST: www.google.com\r\n\r\n");
    while (!feof($connection)) {
        echo fread($connection,256);
    }
    fclose ($connection);
?>

Link to comment
https://forums.phpfreaks.com/topic/105682-fsockopen-help/
Share on other sites

Because it's only getting the content you requested (index.html), the images are likely linked to relatively hence they won't show as they would be hunting on your server for the image location.

 

You could pull the data down and parse it, but that would be a waste of time.

 

This isn't what the socket functions are for, really. Something in-scope would be, say, connecting to a MUD and issuing commands via a web interface.

 

 

Link to comment
https://forums.phpfreaks.com/topic/105682-fsockopen-help/#findComment-541477
Share on other sites

When you display someone else's HTML code on your site, all the relative links will be relative to YOUR site.  If all you want is a php web proxy, Yoctoproxy does a decent job of that.  If you want to make your own proxy, then be warned that it's not easy :)  You'll need to rewrite all those links like yoctoproxy does.

Link to comment
https://forums.phpfreaks.com/topic/105682-fsockopen-help/#findComment-541501
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.