Page 1 of 1
Get folder from address
Posted: Mon Jan 30, 2006 10:31 am
by waradmin
Ok, so I want to write a redirect that uses the folder you are currently in as a value. To clear that up:
Say the user is in the folder myopenspace.net/steve
I want the redirect to take the steve (being the folder) and add that to the redirect
Code: Select all
<?
header('Location: http://www.myopenspace.net/user/?P=steve');
?>
So basicly the steve comes from the folder your in, if you were at
http://www.myopenspace.net/testfolder the redirect would need to go to
http://www.myopenspace.net/user/?P=testfolder
But im looking for this to be dynamic. When a user registers for the site, I want it to copy a index.php file into a directory that is created and the index.php will know to redirect to their profile by using the folder the file is in as the username. Is there a way to do this?
-steve
Posted: Mon Jan 30, 2006 10:33 am
by John Cartwright
Posted: Mon Jan 30, 2006 11:05 am
by waradmin
Im not looking for database use here at all, simply a way to without using a DB get the /_____ and put it in a redirect as /user/?P=_______
-steve
Posted: Mon Jan 30, 2006 11:48 am
by nickman013
waradmin wrote:Im not looking for database use here at all, simply a way to without using a DB get the /_____ and put it in a redirect as /user/?P=_______
-steve
there is no database is that post that he told you to go to. it is exactly what you are looking for too.
Posted: Mon Jan 30, 2006 11:49 am
by josh
As said before, mod_rewrite will do that for you
Posted: Mon Jan 30, 2006 12:48 pm
by waradmin
So what would the file then look like? Would that code be in the header for a redirect or what? I am new to the ModRewrite function.
Thanks for the help and sorry for the misunderstanding on the previous post.
-steve
Posted: Mon Jan 30, 2006 1:20 pm
by nickman013
This is exactly what you are looking for. It probly isnt coded the best that it could, and its probly horrible. But it works, and it is what you are looking for.
make this index.php in every username folder
index.php
Code: Select all
<?
$testArray = explode('/', $_SERVER['PHP_SELF']);
$url = "http://www.myopenspace.net/user/?P=$testArray[1]";
?>
<html>
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=<? echo "$url";?>">
</html>
try it out!
EDIT: IGNORE THE BELOW
nt color="#000000"><?php
Posted: Mon Jan 30, 2006 6:19 pm
by waradmin
Nickman, thanks for that code, it solved many problems. Problem solved.
-steve
Posted: Mon Jan 30, 2006 8:02 pm
by nickman013
Cool, Thanks glad to help you.
I am glad I finally helped somebody and didnt get help from somebody.

Posted: Mon Jan 30, 2006 8:13 pm
by John Cartwright
Your way your going to have to manually put an index file and user folder for every user..
Put the following in an .htaccess file
Code: Select all
RewriteEngine On
RewriteBase /
RewriteRule ^user/([A-Za-z]+)$ /user.php?P=$1
And then visiting the url
http://domain.com/user/bob will transparantly point to user.php with $_GET['P'] as the username
A much cleaner solution IMO
Posted: Mon Jan 30, 2006 8:43 pm
by nickman013
^
indeed.