Website preview script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nibin
Forum Newbie
Posts: 3
Joined: Wed Feb 29, 2012 7:47 am

Website preview script

Post by Nibin »

Hello,

I am very new to PHP coding. I am trying to achieve a task via PHP, regarding which I have been googling around for a few days and now come up with emtpy hands!

Ok, what I need to write is a "website preview script". That is I need to display a website hosted on serverA and pointing elsewhere, from ServerA ( via curl possibly ).

For example: I have configured techsware.in and google.com on ServerA ( of course google.com pointing to their IP ). I need to display the contents of google.com "on my server" , if I call http://techsware.in/google.php which has some curl coding in it! Note, what I have is the domain name ( google.com ) and the IP on which it is hosted on serverA to achieve this. Any way to achieve this?

PS: web server is apache and php version is 5.2

Any help will be highly appreciated!

Thank you,
Nibin.
Nibin
Forum Newbie
Posts: 3
Joined: Wed Feb 29, 2012 7:47 am

Re: Website preview script

Post by Nibin »

Hello,

Just another note - I can achieve this if I put <my IP> google.com in /etc/hosts file ( its Linux ). But I need to run this script for normal users as well, which won't have super user privileges and thus unable to edit /etc/hosts file. So I want to specify somewhere in the PHP script that, google.com points to <my IP>.

Hope someone from this forum will come back a solution :)

Thank you,
Nibin.
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: Website preview script

Post by temidayo »

You can try php stream functions

Here is a code snippet from php.net

Code: Select all

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}
?> 

Nibin
Forum Newbie
Posts: 3
Joined: Wed Feb 29, 2012 7:47 am

Re: Website preview script

Post by Nibin »

Hello Temidayo,

Thanks for your reply!

But I want to load example.com from my own server, where the php script will run ( localhost in fact ); no matter to where example.com is resolving to. For this, I just have the doain name (example.com ) and the IP on which it is hosted on my server.

Hope this makes more sence!

Thank you,
Nibin.
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: Website preview script

Post by temidayo »

Nibin wrote:Hello Temidayo,
...But I want to load example.com from my own server, where the php script will run ( localhost in fact ); no matter to where example.com is resolving to. For this, I just have the doain name (example.com ) and the IP on which it is hosted on my server.
Maybe html frame/iframe is what you need.
Post Reply