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
waradmin
Forum Contributor
Posts: 240 Joined: Fri Nov 04, 2005 2:57 pm
Post
by waradmin » Mon Jan 30, 2006 10:31 am
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
waradmin
Forum Contributor
Posts: 240 Joined: Fri Nov 04, 2005 2:57 pm
Post
by waradmin » Mon Jan 30, 2006 11:05 am
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
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Mon Jan 30, 2006 11:48 am
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.
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Mon Jan 30, 2006 11:49 am
As said before, mod_rewrite will do that for you
waradmin
Forum Contributor
Posts: 240 Joined: Fri Nov 04, 2005 2:57 pm
Post
by waradmin » Mon Jan 30, 2006 12:48 pm
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
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Mon Jan 30, 2006 1:20 pm
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
waradmin
Forum Contributor
Posts: 240 Joined: Fri Nov 04, 2005 2:57 pm
Post
by waradmin » Mon Jan 30, 2006 6:19 pm
Nickman, thanks for that code, it solved many problems. Problem solved.
-steve
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Mon Jan 30, 2006 8:02 pm
Cool, Thanks glad to help you.
I am glad I finally helped somebody and didnt get help from somebody.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Jan 30, 2006 8:13 pm
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
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Mon Jan 30, 2006 8:43 pm
^
indeed.