WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Gonx Proxy - This class is meant to act as an HTTP proxy to serve pages of a remote server as if they were local pages.
Categories : PHP, PHP Classes, HTTP Click here to Update Your Picture
Ben Yacoub Hatem
Date : May 24th 2004
Grade : 1 of 5 (graded 3 times)
Viewed : 6847
File : 3884.tar.gz
Images : No Images for this code example.
Search : More code by Ben Yacoub Hatem
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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;
?>



Easy upload class
Categories : PHP Classes, Filesystem, HTTP, PHP
Request Method Class - seful for situations like form processing or API development. Requires PHP5 for the magic __call() method.
Categories : PHP, PHP Classes, HTTP, Headers
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
Simple and fast user authentication
Categories : PHP, PHP Classes, Authentication
Form is a utility class for generating html forms. It provides form initialization and regex based data validation (both server and client side) with a convenient interface. This version obsoletes version 1.0a
Categories : HTML, PHP, PHP Classes, Regexps
shopping cart class with add/edit/delete product functionality.
Categories : PHP, PHP Classes, Ecommerce
HTML_Graphs provides a simple PHP interface for creating pure HTML charts.
Categories : Graphics, PHP, PHP Classes, Charts and Graphs
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Array Insertion
Categories : PHP, PHP Classes, Arrays
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
DBE - Database Expander: Edit PostgreSQL individual database tables online via your Web browser!
Categories : PostgreSQL, Complete Programs, Databases, PHP Classes, PHP
cPanel Email Accounts Creator
Categories : PHP, PHP Classes, Email, Form Processing, Web Services
Menu in sliding bar or tree style. Handles frames by using small amount of javascript. Handles external and internal pages. Allows custom code to replace a menu item.
Categories : PHP Classes, PHP, Java Script, DHTML
HTTP gzip compression
Categories : PHP, PHP Classes, Compression, Zlib