sotre url in a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raj74
Forum Newbie
Posts: 1
Joined: Sat Jan 10, 2004 6:06 am

sotre url in a variable

Post by raj74 »

hi,

i am a newbie, how can i store the current url in a variable.
OR
redirect user based on virtual directory for example if user types http://localhost/TM then he should redirect to tm.php

If user types http://localhost/king then he should go to king.php

I also tried the server variable like $PHP_SELF nothing is working.any help

thanks in advance
raj
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, the current uri is already in a variable, $_SERVER['PHP_SELF']. As for the second bit, you can force 'foo' to be parsed as a PHP file using an apache ForceType Directive (google for it ;) ). It just means you name you files _without_ the .php extension.
Alternatively you could use a mod_rewrite to rewrite foo to foo.php but that's more trouble that it's worth and isn't really an option.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Run this page:

Code: Select all

<?php
phpinfo();
?>
Check the bottom of the page generated (the $_SERVER[*]) for more ideas on what you might be able to use. They are listed as _SERVER but in a php script, add the $ before them.
Post Reply