It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum Script-archive

PHP, URL Masking - Script

Share your completed scripts.

Moderator: Malcolm

PHP, URL Masking - Script

Postby HotNoob on Wed Sep 22, 2010 3:14 am

Here is a way to mask a url, for example, lets say you want to use http://somesite.com to display the page http://CCGames.tk without using an IFrame or any of that other junk, while STILL having the same url; aka url masking.

Code: Select all
//http://somesite.com
<?php
  $URL = "http://CCGames.tk"; // the url of the page that you want to load.
  $base = '<base href="'.$URL.'">';
  $host = preg_replace('/^[^\/]+\/\//','',$URL);
  $tarray = explode('/',$host);
  $host = array_shift($tarray);
  $URI = '/' . implode('/',$tarray);
  $content = '';
  $fp = @fsockopen($host,80,$errno,$errstr,30);

  if(!$fp)
  {
        echo "Unable to open socked: $errstr ($errno)\n"; exit;
  }

  fwrite($fp,"GET $URI HTTP/1.0\r\n");
  fwrite($fp,"Host: $host\r\n");

  if( isset($_SERVER["HTTP_USER_AGENT"]) )
  {
     fwrite($fp,'User-Agent: '.$_SERVER["HTTP_USER_AGENT"]."\r\n");
  }

  fwrite($fp,"Connection: Close\r\n");
  fwrite($fp,"\r\n");

  while (!feof($fp))
  {
    $content .= fgets($fp, 128);
  }

  fclose($fp);

  if( strpos($content,"\r\n") > 0 )
  {
        $eolchar = "\r\n";
  }
  else
  {
        $eolchar = "\n";
  }

  $eolpos = strpos($content,"$eolchar$eolchar");
  $content = substr($content,($eolpos + strlen("$eolchar$eolchar")));

  if( preg_match('/<head\s*>/i',$content) )
  {
        echo( preg_replace('/<head\s*>/i','<head>'.$base,$content,1) );
  }
  else
  {
        echo( preg_replace('/<([a-z])([^>]+)>/i',"<\\1\\2>".$base,$content,1) );
  }
?>


Hope I helped! :D
HotNoob
100+ Club
 
Posts: 169
Joined: Sun May 02, 2010 1:38 am

Re: PHP, URL Masking - Script

Postby AgenceElysium on Mon Jan 03, 2011 8:03 pm

Amazing :D Been looking for this for hours. I almost lost hope trying to do URL masking using htaccess.
AgenceElysium
 
Posts: 1
Joined: Mon Jan 03, 2011 7:54 pm


Who is online

Users browsing this forum: No registered users and 0 guests

cron