PHPTennis: PHP built webpage viewer

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
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

PHPTennis: PHP built webpage viewer

Post by phice »

I've been making a small webpage viewer, which will use the server to download the webpage, fix it's links, and show the HTML given.

I'll start it off:

Code: Select all

<?php
if (!$url) { die("You need to set your url. Example: browser.php?url=http://www.yourdomain.com/"); }
$strings = $_SERVER["QUERY_STRING"];
$url = str_replace("url=", "", $strings);

?>
<html>
<base href="<? echo $url; ?>">
<head>
<title>Browser - <? echo $url; ?></title>
</head>
<?
$lines = file($url);
foreach ($lines as $line_num => $line) { 

   $line = eregi_replace("href=/", "hrXef=$PHP_SELF?url=$linkback/", $line);
   $line = eregi_replace("href="/", "hrXef="$PHP_SELF?url=$linkback/", $line);
   $line = eregi_replace("href="", "hrXef="$PHP_SELF?url=", $line);
   $line = eregi_replace("href='/", "hrXef='$PHP_SELF?url=$linkback/", $line);
   $line = eregi_replace("href='", "hrXef='$PHP_SELF?url=", $line);
   $line = eregi_replace("href=", "$PHP_SELF?url=", $line);
   $line = str_replace("hrXef=", "href=", $line);

   echo $line . "\n";
}
?>
Rules
-Add atleast 3 lines
-No external images, php files, etc will be used
-all php coding above shall reside in one php document (browser.php)

Let the games begin!
Image Image
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php
// #1, vk, 020235, n
// #1, all short to full tags
if (!$url) { die("You need to set your url. Example: browser.php?url=http://www.yourdomain.com/"); }
$strings = $_SERVER["QUERY_STRING"];
$url = str_replace("url=", "", $strings);

?>
<html>
<base href="<?php echo $url; ?>">
<head>
<title>Browser - <?php echo $url; ?></title>
</head>
<body><!-- #1, make it a complete document -->
<fieldset><legend><?php echo htmlentities($url) ?></legend><!-- #1, show in fieldset -->
<?php
$lines = file($url)
		or die('File not found'); // #1, added 'File not found'
foreach ($lines as $line_num => $line) {

   $line = eregi_replace("href=/", "hrXef=$PHP_SELF?url=$linkback/", $line);
   $line = eregi_replace("href="/", "hrXef="$PHP_SELF?url=$linkback/", $line);
   $line = eregi_replace("href="", "hrXef="$PHP_SELF?url=", $line);
   $line = eregi_replace("href='/", "hrXef='$PHP_SELF?url=$linkback/", $line);
   $line = eregi_replace("href='", "hrXef='$PHP_SELF?url=", $line);
   $line = eregi_replace("href=", "$PHP_SELF?url=", $line);
   $line = str_replace("hrXef=", "href=", $line);

   echo $line . "\n";
}
?> 
</body></html>
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Code: Select all

<?php 
// #1, vk, 020235, n 
// #1, all short to full tags 
if (!$url) { die("You need to set your url. Example: browser.php?url=http://www.yourdomain.com/"); } 
$strings = $_SERVER["QUERY_STRING"]; 
$url = str_replace("url=", "", $strings); 

?> 
<html> 
<base href="<?php echo $url; ?>"> 
<head> 
<title>Browser - <?php echo $url; ?></title> 
</head> 
<body><!-- #1, make it a complete document --> 
<fieldset><legend><?php echo htmlentities($url) ?></legend><!-- #1, show in fieldset --> 
<?php 
$lines = file($url) 
      or die('File not found'); // #1, added 'File not found' 
foreach ($lines as $line_num => $line) { 

   $line = eregi_replace("(action|href)=/", "(acXtion|hrXef)=$PHP_SELF?url=$linkback/", $line); 
   $line = eregi_replace("(action|href)="/", "(acXtion|hrXef)="$PHP_SELF?url=$linkback/", $line); 
   $line = eregi_replace("(action|href)="", "(acXtion|hrXef)="$PHP_SELF?url=", $line); 
   $line = eregi_replace("(action|href)='/", "(acXtion|hrXef)='$PHP_SELF?url=$linkback/", $line); 
   $line = eregi_replace("(action|href)='", "(acXtion|hrXef)='$PHP_SELF?url=", $line); 
   $line = eregi_replace("href=", "href=$PHP_SELF?url=", $line); 
   $line = str_replace("hrXef=", "href=", $line); 
   $line = str_replace("acXtion=", "action=", $line); 

   echo $line . "\n"; 
} 
?> 
</body></html>
eregi may be messed up with the action/href switch... I'm not too good with eregi ;]
Image Image
Post Reply