Frames With PHP fsockopen

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
ORiGIN
Forum Newbie
Posts: 20
Joined: Sat Nov 11, 2006 11:17 pm

Frames With PHP fsockopen

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

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

echo $page ? $page : 'Page is currently offline';
:wink:
ORiGIN
Forum Newbie
Posts: 20
Joined: Sat Nov 11, 2006 11:17 pm

Post by ORiGIN »

I still dont see the google logo, did I configure Apache or php wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
ORiGIN
Forum Newbie
Posts: 20
Joined: Sat Nov 11, 2006 11:17 pm

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
ORiGIN
Forum Newbie
Posts: 20
Joined: Sat Nov 11, 2006 11:17 pm

Post 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.
ORiGIN
Forum Newbie
Posts: 20
Joined: Sat Nov 11, 2006 11:17 pm

Post 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?
ORiGIN
Forum Newbie
Posts: 20
Joined: Sat Nov 11, 2006 11:17 pm

Post 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.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

You should read up on the ternary operator; more specifically: what it does and how/when to use it.
ORiGIN
Forum Newbie
Posts: 20
Joined: Sat Nov 11, 2006 11:17 pm

Post by ORiGIN »

Okay, I'll read that. Thanks for all of the help.
Post Reply