Page 1 of 1

Frames With PHP fsockopen

Posted: Sat Nov 11, 2006 11:28 pm
by ORiGIN
Hello, I am new to php and these forums.

I am interested in how to make a page with just a frame. I want that frame to contain a website if it is online, but if it is offline I just want the page to say so.
If you click links I want it to stay on the current site, but for the frame to change to that link...

I have found out some of my help here:

Code: Select all

<?php
error_reporting(0);
$fp = fsockopen("www.google.com", 80);
if (!$fp) {
   echo 'I Am Sorry, But This Website Is Currently Down.'; //"$errstr ($errno)<br />\n";
} else {
   $out = "GET / HTTP/1.1\r\n";
   $out .= "Host: http://www.google.com\r\n";
   $out .= "Connection: Close\r\n\r\n";

   fwrite($fp, $out);
   while (!feof($fp)) {
       echo fgets($fp, 128);
   }
   fclose($fp);
}
?>
But it shows a bunch of text at the top that I do not want, and it doesn't show images. How do I get this all in a frame and have it show images and get rid of all of that text at the top?

The reason for all of this is that I am going to try and setup one of my old pcs to be a web server. I don't want it on all of the time and don't want users to see that "Page cannot be displayed" page. I have got it almost all done. I got a new internet connection and I got trendmicro internet security 2007 on it. If I want to make it more secure what would anybody recommend?

Thanks

Posted: Sat Nov 11, 2006 11:33 pm
by John Cartwright

Code: Select all

$page = file_get_contents('http://google.ca');

echo $page ? $page : 'Page is currently offline';
:wink:

Posted: Sat Nov 11, 2006 11:44 pm
by ORiGIN
I still dont see the google logo, did I configure Apache or php wrong?

Posted: Sat Nov 11, 2006 11:48 pm
by feyd
The requested pages would have to hard code full URL references for you to see pages you are proxying. You will have to parse the page and convert them to either user your proxy again or full URLs to the originals.

Posted: Sun Nov 12, 2006 12:00 am
by ORiGIN
Wow, I guess I should read up on some tuts and get more experience in php before I can do that. Thanks for the help.

Posted: Sun Nov 12, 2006 12:04 am
by John Cartwright
Just make sure your site is using full urls :wink:

for instance, try that little snipplet on yahoo.com, and you'll see the images and styles appearing fine.

Posted: Sun Nov 12, 2006 12:35 am
by ORiGIN
Does anyone know how I would do that with modX cms?

I did this like someone said in those forums:
Turn off the "Image Rewrite Paths" in the manager, and change the "Resource URL" from "http://mydomain.com/assets" to just "/assets/" (no quotes, of course).
But that didn't do it.

Posted: Sun Nov 12, 2006 1:26 am
by ORiGIN
I figured it out it was in the templates css.

One more thing, how would I make the frame go to a page on the same server if the site is down instead of it just saying something? Or is there a way to make it echo html instead of the words?

Posted: Sun Nov 12, 2006 9:53 am
by ORiGIN
I tried adding more lines, like this:

Code: Select all

echo $page ? $page : '<h2>Site Unavailable<h2>';
echo $page ? $page : '<br> <h4>I Am Sorry, But The Website Is Offline</h4>';
echo $page ? $page : '<br><br>Please Come Back At A Later Time';
echo $page ? $page : 'This Website Is Currently Offline';
This works when the page isn't found, but if it is found it adds 4 of the same page right below eachother.

Posted: Sun Nov 12, 2006 10:03 am
by jayshields
You should read up on the ternary operator; more specifically: what it does and how/when to use it.

Posted: Sun Nov 12, 2006 10:41 am
by ORiGIN
Okay, I'll read that. Thanks for all of the help.