Jump to content

Help with redirection script


freaka

Recommended Posts

I posted this earlier but i think maybe the subject was a bit distracting. maybe this will work.

 

-------

 

I would like to write a script in PHP that would allow me to link things like this:

 

index.php?p=news  < and have this goto the news page

and

index.php?download=moo.mp3  < and have this download the file

 

but what i would really like is if i could not even have to write the index.php part. for example:

 

http://DJFreaka.com/?p=news

and

http://DJFreaka.com/?download=moo.mp3

 

I had written a script similar to this once before, but i dont remember how. also i want to figure out how to make it so when i link to files like this, the real location isnt revealed. the script i wrote redirected to the file, but then the address bar read "http://djfreaka.com/example.html" when i did something like ?p=example.

 

so if anyone can help me out, i would be deeply appreciative. thanks a lot for your help.

Link to comment
https://forums.phpfreaks.com/topic/41865-help-with-redirection-script/
Share on other sites

sorry had to modify a couple times

 


$p = $_GET['p'];

// $p is nothing
if(is_empty($p) || strlen($p) < 1){
  $p = "default_file";
}

  $file = 'PATH_TO_INCLUDES/'.$p.'.php';

  if(file_exists($file)){
    include "$file";
  }else{
    include "error.php";
  }
   

ok, i read the rewrite tutorial and it helped a bit especially with the .htaccess file, but now when i took that code above and used it I get this:

 

Fatal error: Call to undefined function: is_empty() in /hsphere/local/home/fre4ka/djfreaka.com/index.php on line 5

 

 

Also, I tried this and it works just fine. I don't know if it helps but this works.

 

<html>
   <head>
      <title>Second mod_rewrite example</title>
   </head>
   <body>
      <p>
         The requested page was:
         <?php echo $_GET['page']; ?>
      </p>
   </body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.