PHP help

Associate
Joined
18 Oct 2002
Posts
1,548
Location
Cheltenham
I am not very good with this PHP or SQL malarky. Infact, I couldn't write it for toffee but I can follow bits.

I have downloaded this free script called PHP Login Script 2.0 and the code redirects all users to the same page (myaccount.php) - I would like each user to be redirected to their specific page though when logging in.

i.e.
- Person 1 logs in and is redirected to Page1.php
- Person 2 logs in and is redirected to Page2.php

In the database, I use to have 3 fields for id, username and password but I have just created a new field for 'destination' where I thought the page name they were allocated to could be stored.

For the code I currently have for the redirection, I have the standard:

header("Location: myaccount.php");

I appreciate this post is probably quite vague and I need to put more PHP in to identify what the destination page is for each user when they log in so I would appreciate any guidance etc on this.

Thanks
 
Thanks for your input so far.

I basically want each user to be able to access their own individual page which each will have some standard links to downloadable docs.

The page they will be redirected to will be completely standard but I just need the correct coding which will redirect the user, when they have logged in, to their relevant page.

Ideally, my client will use this front-end form I have to create a username and password (along with id) in the database. Then he would log in to phpMyAdmin, edit the user entry and manually enter the page name (he would manually create this page and upload it via FTP) he would like the user to be redirected to when they log in.

dblayout.gif


I manually created the 'destinations' field alongside my username/password entry and entered the page client1.php as an example. Now, when I go to log in using my username and password, i would like to be redirected to client1.php, whereas, at the moment, the code within the PHP login file is pointing to that header / myaccount.php at the moment.

Does this help?

p.s. suarve, I tried entering your coding and got an error:

Parse error: syntax error, unexpected T_STRING in /home/misbour/public_html/new/login/login.php on line 54

As I said, I'm useless at PHP but I'm guessing something in that sql line is wrong, maybe?
 
Last edited:
Thanks for the replies again. I think I'm just stupid. Hopefully someone can help again!

Right, my file currently contains:

Code:
$sql = "SELECT destination from users WHERE id = '1' LIMIT 1";  
			
$redir_page = 'clients1.php';

header('Location: '.$redir_page.'');

In the database, I created an additional field called 'destination' (does it matter if the Type = text or does it need to be varchar(200) or anything particular?!). I edited my entry in the database and under 'destination', put down 'client1.php' and hit save.

For each login, I would like a different page name so each user is redirected to their own page. Please can someone help me with the PHP code so it detects what username/password is logging in and then view the value under destination and redirect them to that page?

I can basically set up the PHP template and upload it via FTP, then put the page name in the database row. I just need the login form to detect the user and redirect accordingly.

Thanks
 
Thanks for that code - the client is use to working in phpMyAdmin and they're not paying either! For a family friend.

Re the code above:

Code:
/* Above, log in user and check password. If correct return userid from database - have used 1 as an example */
$user_id = 1;
//Your sql query to select the desination from your users database
$sql = "SELECT destination from users WHERE id = '{$user_id}' LIMIT 1";

What would be the PHP for querying the database and pulling out the relevant ID when they have logged in?

I have one account so far which is mine and the ID is 54. If I change the code above to be id = 54, then it will pull out the destination value but I obviously hard coded the id part in. So, basically, would be to the code to detect what username and password has logged in so it can detect the ID, then detect the destination for that ID?

Thanks!
 
Back
Top Bottom