Re: curl equivalent in PHP
| From: | Matijn Woudt | Date: | Sat, 03 Mar 2012 00:16:36 +0000 |
| Subject: | Re: curl equivalent in PHP | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316861@lists.php.net to get a copy of this message | ||
On Fri, Mar 2, 2012 at 6:09 PM, Nibin V M <nibinvm@gmail.com> wrote:
> Hmm..I am a php newbie ( just started learning it )...
>
> what my need is to display website from my server always for a
> non-registered domain.This is the code I use now to display the website
>
> <?php
> $opts = array(
> 'http'=>array(
> 'method'=>"GET",
> 'header'=>"Accept-language: en\r\n" .
> "Cookie: foo=bar\r\n"
> )
> );
>
> $context = stream_context_create($opts);
>
> $fp = fopen('http://www.blahblah.com', 'r',
> false, $context);
> fpassthru($fp);
> fclose($fp);
> ?>
>
> Of course blahblah.com isn't registered yet. This will load the index page
> of blahblah.com fine ( since I use hosts file to resolve blahblah.com on
> the server ). But if we click on any link, it will give "server not found"
> error since my "local machine" is trying to resolve blahblah.com this time.
> I need to avoid it and want to load my domain "always" from the server when
> I click any link on the webpage, etc .
>
> How can I modify the above code to make it work! If possible, I request
> somebody to tell me the exact code that I need to change in the above
> script - since most of the php part is still greek to me :)
>
> Thank you,
Have you actually read/tried Daniel Browns reply?
The following seems to be all you need...
<?php
echo
str_replace('blahblah.com','localhost',file_get_contents('blahblah.com'));
?>