Proxy with PHP !!!

Discussion in 'PHP' started by pulikuttann, Mar 27, 2007.

  1. #1
    I know about PhpProxy .

    But I want to create one small by myself.
    I am not understanding the codes from PHPProxy.
    Can anyone plz help me with the idea/logic ?
     
    pulikuttann, Mar 27, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    You get the page from the server, parse certain html tags to fix images / strip scripts etc then echo the html, they are actually very simple
     
    krakjoe, Mar 27, 2007 IP
  3. pulikuttann

    pulikuttann Banned

    Messages:
    1,839
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #3
    parsing html ???
    Did I need to create some parse tree ???
    Plz make it clear ?
     
    pulikuttann, Mar 27, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    I don't have that much time this afternoon, but this should / could get you started :
    
    <?
    class proxy
    {
    	static $cache;
    	static $url;
    	
    	function __construct( $url = null, $strip = array( ), $adjust = array( ) )
    	{
    		if( !$url ) return;
    		self::$url = preg_replace("/\\/$/si", "", $url );
    		if( !(self::$cache = file_get_contents( self::$url ) ) ):
    			self::$cache = sprintf( "Cannot connect to %s", self::$url );
    		elseif( !self::parse() ):
    			self::$cache = sprintf( "Cannot parse %s", self::$url );
    		endif;	
    		
    		$form = "<center>".
    				"<form action=\"\" method=\"post\">".
    			    "URL : <input type=\"text\" name=\"url\">".
    			    "<input type=\"submit\" value=\"Browse\">".
    			    "</form>".
    				"</center>\n";
    		
    		echo preg_replace("#<body (.*?)>#si", "<body $1>" . $form, self::$cache );
    		
    	}
    	function parse( )
    	{
    		$clean = self::$cache;
    		$search = "/((src|href|background|action)=\"([^:,^>,^\"]*)\")/i";
    		preg_match_all( $search, self::$cache, $temp );
    		$search = array_unique( $temp[3] );
    		$clean = str_replace("./", self::$url . "//", $clean );
    		foreach( $search as $makeup )
    		{
    			if( $makeup != "/" )
    		 	$clean = str_replace( $makeup, self::$url . "//$makeup", $clean );
    		}
    		self::$cache = trim( $clean );
    		
    		if( self::$cache)
    		return true;
    	}
    	
    }
    new proxy( @$_REQUEST['url'] );
    ?>
    
    PHP:
    The next step would be to replace all the links with links that go back through the proxy.
     
    krakjoe, Mar 27, 2007 IP
  5. pulikuttann

    pulikuttann Banned

    Messages:
    1,839
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thankz
    Can I get some sites that can help me to create my php proxy ???
    Only Ideas !!!
    Thankz again for ur great help
     
    pulikuttann, Mar 27, 2007 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    That was off the top of my head, if it were me that was making one, I would look at the source of others to see what features I would keep and see what features I would have to make; it shouldn't be too hard if you know php to make a decent lightweight proxy without a tutorial.
     
    krakjoe, Mar 28, 2007 IP