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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.