freaka Posted March 8, 2007 Share Posted March 8, 2007 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 More sharing options...
benjaminbeazy Posted March 8, 2007 Share Posted March 8, 2007 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"; } Link to comment https://forums.phpfreaks.com/topic/41865-help-with-redirection-script/#findComment-203025 Share on other sites More sharing options...
pocobueno1388 Posted March 8, 2007 Share Posted March 8, 2007 You will have to use mod_rewrite. <a href="http://www.workingwith.me.uk/articles/scripting/mod_rewrite">Tutorial</a> Link to comment https://forums.phpfreaks.com/topic/41865-help-with-redirection-script/#findComment-203055 Share on other sites More sharing options...
freaka Posted March 9, 2007 Author Share Posted March 9, 2007 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 Link to comment https://forums.phpfreaks.com/topic/41865-help-with-redirection-script/#findComment-203436 Share on other sites More sharing options...
freaka Posted March 9, 2007 Author Share Posted March 9, 2007 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> Link to comment https://forums.phpfreaks.com/topic/41865-help-with-redirection-script/#findComment-203440 Share on other sites More sharing options...
freaka Posted March 9, 2007 Author Share Posted March 9, 2007 ??? Link to comment https://forums.phpfreaks.com/topic/41865-help-with-redirection-script/#findComment-203558 Share on other sites More sharing options...
freaka Posted March 9, 2007 Author Share Posted March 9, 2007 Never mind i got rid of if statement because the is_empty function was undeclared and i dont know enough php to understand that function. thanks for trying though. you can test my work by going to http://djfreaka.com/index.php?p=news Link to comment https://forums.phpfreaks.com/topic/41865-help-with-redirection-script/#findComment-203564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.