Forum Moderators: coopster
I am totally stumped on trying to redirect users to their unique url page after login.
So far, I have the login script and verification system working.
My login script looks something like this:
if(form is submitted){//define username && password;
//register username && password into session;
//redirect to index.php;
}
else{
//redirect back to login page;
}
The problem here is that after the user logs in, they are ALL taken to the same url: index.php.
I thought of just specifying the redirect to something like this:
header(http://mysite/$username);. The problem is, I don't know the first step in doing that and how to create each of those unique pages?
I would probably need to create those unique pages at the registration level right? But how would I do that (create unique user url pages)? Would I need to use mod-rewrites? Thanks.
In the root of your web project, you want to create a .htaccess with something like the following, (this is untested)
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/user/
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ userpage.php [L,QSA] This code grabs all URLS that begin with /user/, so it would grab /user/geoff/, /user/dave/, etc, and redirects internally to a PHP file in the root called userpage.php.
This PHP file can then parse the URL they inputted picking out the relevant information and then determine what happens.
Hope this makes sense.
But, by the power of Google, I found out that,
-f is a file, so !-f means that it shouldn't be an existing file
-d is a directory, so !-d means that it shouldn't be an existing directory
L means the last RewriteRule to be run. No more will be run after this.
And QSA is "Query String Appendage", which means that all your $_GET stuff will be passed along with the internal redirect.