Forum Moderators: coopster

Message Too Old, No Replies

Help redirecting users to unique page after login

user unique redirect

         

rodriguez1804

8:16 pm on Jul 22, 2008 (gmt 0)

10+ Year Member



Hi everyone!

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.

Sekka

10:39 pm on Jul 22, 2008 (gmt 0)

10+ Year Member



'mod_rewrite' would certainly be your friend here. It would allow you to redirect all these user URLs to a single PHP file internally and let the PHP file display the relevant content.

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.

rodriguez1804

10:57 pm on Jul 22, 2008 (gmt 0)

10+ Year Member



Thanks for the help. This is just what I was looking for. By having the userpage.php, it would give me greater flexibility on the actions to be taken. Thanks again!

rodriguez1804

10:58 pm on Jul 22, 2008 (gmt 0)

10+ Year Member



by the way, would you be so kind as to explain what the !-f, !-d and [L,QSA] parameters mean?

Sekka

11:11 pm on Jul 22, 2008 (gmt 0)

10+ Year Member



To be 100% honest, not a clue. I found that code a while ago and used it since.

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.