|
|
|
|
|
|
| |
It fetches remote pages and translates all HTML tags of links and images, background image attributes and external style sheet references to use the URLs based on the current script URL.
gonxproxy.class.php
| <?php
/**
* gonxproxy class : Just a HTTP Proxy
*
* @package
* @author Ben Yacoub Hatem <hatem@php.net>
* @copyright Copyright (c) 2004
* @version $Id$ - 07/04/2004 13:48:08 - gonxproxy.class.php
* @access public
**/
class gonxproxy{
/**
* Constructor
* @access protected
*/
function gonxproxy(){
}
/**
*
* @access public
* @return void
**/
function version(){
return "1.0.1";
}
/**
* Return html form of GonxProxy
*
* @access public
* @return void
**/
function form(){
global $url;
if (!ereg("http",$url) and $url!="") {
$url = base64_decode($url);
}
return "\n\n<!-- GonxProxy Form -->
<style><!--
.gonxproxy {
background-color: #F6F6F6;
margin: 4px;
padding: 4px;
border: 1px solid #CCCCCC;
}
input.gonxproxy {
background-color: white;
border: 1px solid #CCCCCC;
}
//-->
</style>
<form method=get action=\"?\">
<table class=gonxproxy width=600 cellpadding=4 cellspacing=10>
<tr><td>
<input name=url value=\"$url\" size=70 class=gonxproxy>
<input type=submit class=gonxproxy value=Submit><br/><br/>
<input type=hidden name=proxy value=1>
<font size=1>GonxProxy version ".gonxproxy::version()." - Author : Ben Yacoub Hatem - Copyright © <a href=\"http://www.dynamix-tn.com/v2/home/\" target=_blank>Dynamix SARL</a> 2004-2005 </font>
</td></tr></table>
</form>
<!-- /GonxProxy Form -->\n\n";
}
/**
* Retreive a url
*
* @access public
* @return void
**/
function connect($_url){
$file = @fopen( $_url, "rb" );
if (!$file) {
return "<font size=2 color=red>Error while opening URL</font>";
}
$line = fread( $file, 1024 );
if( eregi( "html", $line ) ){
fclose( $file );
$html = implode('',@file($_url) );
return gonxproxy::parse_html($html,$_url);
} else {
echo $line;
fpassthru( $file );
@fclose( $file );
exit;
}
}
/**
* Parse a HTML Page, remove JScript, convert Urls and return it.
*
* @access public
* @return void
**/
function parse_html($_data,$_url){
$matches = preg_match_all( "/(href|src|background|@import) *=? *\"(.*)\"/Ui", $_data, $regs );
foreach($regs[2] as $k=>$v){
$_data = str_replace($v,gonxproxy::chg_url($v,$_url), $_data);
}
return $_data;
}
/**
* Convert an URL to a GONX formatted url
*
* Original function code is taken from GURL v2.1 BETA
* by Bob Matcuk (BMatcuk@Users.SourceForge.Net)
* http://gurl.sourceforge.net
*
* @access public
* @return void
**/
function chg_url($piece,$url){
$url_elements = explode("/",$url );
$url_file = ( preg_match( "/\/$/i", $url ) ) ? 0 : 1;
if( preg_match( "/(.*)\#(.*)/", $piece, $regs ) ){ // Links to an anchor (#)
return ( ( $regs[1] == "" ) ? "" : gonxproxy::chg_url( $regs[1],$url ) ) . "#" . $regs[2];
} else if( preg_match( "/http:\/\/(.*)/i", $piece, $regs ) ){ // http:// form
$piece = $regs[1];
} else if( preg_match( "/^\//i", $piece ) ){ // starts with / form
$piece = $url_elements[0] . $piece;
} else if( preg_match( "/^\.\/(.*)/i", $piece, $regs ) ){ // single dots
$piece = $regs[1];
if( $url_file ){
for( $i = sizeof( $url_elements ) - 2; $i >= 0; $i-- ){
$piece = $url_elements[$i] . "/" . $piece;
}
} else {
$piece = $url . $piece;
}
} else if( preg_match( "/^(\.\.\/)+(.*)/i", $piece, $regs ) ){ // double dots
$tok = explode( "/", $piece );
$i = 1 + sizeof( $tok ) - 2;
if( $url_file ){
$i++;
}
$piece = $regs[2];
if( sizeof( $url_elements ) <= $i ){
$piece = $url_elements[0] . "/" . $piece;
} else {
for( $j = sizeof( $url_elements ) - $i; $j >= 0; $j-- ){
$piece = $url_elements[$j] . "/" . $piece;
}
}
} else {
if( $url_file ){
for( $i = sizeof( $url_elements ) - 2; $i >= 0; $i-- ){
$piece = $url_elements[$i] . "/" . $piece;
}
} else {
$piece = $url . $piece;
}
}
if( !( preg_match( "/(\/$|\..+$)/i", $piece ) && preg_match( "/\//i", $piece ) ) ){ // must end in / or file extension
$piece .= "/";
}
if (substr($piece,strlen($piece)-1,1 )=="/") {
$piece = substr($piece,0,strlen($piece)-1 );
}
return "?url=".base64_encode($piece);
}
}
?> | |
Usage Example
| <?php
/**
* gonxproxy Index
*
* @package
* @author Ben Yacoub Hatem <hatem@php.net>
* @copyright Copyright (c) 2004
* @version $Id$ - 09/04/2004 14:45:36 - index.php
* @access public
**/
require_once("gonxproxy.class.php");
@error_reporting(0); // Don't report error
@extract($_GET); // if register globals if off
if (isset($url) and $url!="" and $proxy==1) {
$res = gonxproxy::connect($url);
} elseif(isset($url) and $url!="" and !isset($proxy)){
$res = gonxproxy::connect(base64_decode($url));
}
$res .= gonxproxy::form(); // Add GonxProxy form
echo $res;
?> | | |
|
| Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem | | | Easy upload class Categories : PHP Classes, Filesystem, HTTP, PHP | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Authorize.net AIM Interface Class v1.0.0 Categories : PHP, PHP Classes, Ecommerce, Payment Gateways | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | | | News management class Categories : PHP, PHP Classes, Beginner Guides | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself. Categories : PHP, PHP Classes, Templates, Complete Programs | | | RSS parser.
Parses RSS into an array. Quick and nasty but does the job.
No checking is done for correct Tags, only correct XML.
PHP4 needed to display result (uses print_r). Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS) | | | MS Word Mail Merge Automation (COM) Categories : PHP, PHP Classes, COM | | | Very minimal templating engine Categories : PHP, PHP Classes, Templates | | | ElfReader: An ELF (Executable and Linking Format) header information in PHP. Shows how to use the UNPACK function to read data. Categories : PHP, Linux, PHP Classes | | | Simple Password example Categories : PHP, Authentication, Security, HTTP | | | an example of the cyberlib payment class Categories : PHP, PHP Classes, Ecommerce, Credit Cards | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | |
|
|
|