PDA

View Full Version : returning to previous page


red_rose
01-28-2007, 11:53 AM
hello there

i have some questions to ask. i have a reservation page in my website but this page can only be viewed by users who have logged in. this means at the home page, whenever the user click on reservation link, it will redirect to the respective page. so now, let say if the user is not logged in into the system, then the login.php page should be displayed and the moment the user log in, i want the reservation page to be displayed. because in the login.php script, if the user is a student, then student.php will be displayed once the student log in. but in my case for reservation, when the login.php is displayed, it will redirect the student to student.php and i do not want that to happen. how can i code the script so that after login, the student will be redirected to reservation again, means the page that he/she wanted to view.

any help will be appreciated. thank you

davidj
01-28-2007, 12:46 PM
ok...

if someone clicks on reservations but are not loggd in >> redirect to login

if logged in sucessfully >> display reservations

red_rose
01-28-2007, 01:21 PM
hie david,

yes you are right. but in the login.php, the default page for redirection is not reservations. i hope you get what i mean. after redirecting to login, i want the reservation page to be displayed. so that's why i don't know how to do this for reservations.

thanks for your help

davidj
01-28-2007, 02:04 PM
post your login.php code

red_rose
01-28-2007, 03:24 PM
here is the login.php code :


<?php
//here is the connection to the database

session_start();

$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];

if($userid && $password) {
$query = sprintf("SELECT * FROM users where user_name = '$userid' and user_password = '$password'");
$result = @mysql_query($query);
$row = @mysql_fetch_array($result);
}

if($row) {
$_SESSION['userid'] = $row['user_id'];
if($row['access_level'] == 1)
{
header("location:admin.php");
exit;
}
elseif($row['access_level'] == 2)
{
header("location:student.php");
exit;
}
else
{
header("location:landlord.php");
exit;
}

}
elseif($submitted){
echo "You dont exist in the system";
}
?>

davidj
01-28-2007, 04:02 PM
cant you just change the header("location" method to the page you want if the user logs on successfully?

//*********************

I like your coding style.
dont you just love nice simple code. Much easier to read than what Dreamweaver spews out and its more logical

big high five from me

red_rose
01-28-2007, 04:14 PM
hey david, thanks alot :)

actually you know what, i learned this coding style from you, by going through your video tutorials. hehe

ok, in this login script, u see once the user log in, there are default pages to be redirected to according to the user access level. means, when student sign in, go to default student.php n etc. are you trying to say to change the location to reservation page?

for an easier example, look at this dreamweaver club site. when i first found this website, i wanted to post a new thread before becoming a member. when i clicked on "new thread", it redirected me to login page and once i registered and logged in, i saw the page where i can post a thread.

that's what i meant to do to my page.

i hope it's much more clearer now, or maybe i got your solution wrong? im abit lost here. hope you can give me further explanation of what you meant.

thanks alot david, really appreciate it

davidj
01-28-2007, 04:46 PM
if a user has tried to go to the reservation.php page without logging on he is taken to the register.php page then taken to the reservation.php but only if they chose the reservation.php before. If they did not click the reservation.php then they are just sent to the reservation_successfull.php

red_rose
01-28-2007, 04:56 PM
if a user has tried to go to the reservation.php page without logging on he is taken to the register.php page then taken to the reservation.php


this is what i don't know how to do. how should i change the coding to do this?


If they did not click the reservation.php then they are just sent to the reservation_successfull.php


why they are sent to reservation_successfull.php? this happens only when they have reserved a room right? once they can see reservation.php, they can reserve a room and then only sent to reservation_successfull.php right?

davidj
01-28-2007, 05:01 PM
im confused

cant you just change the header redirect

red_rose
02-03-2007, 12:18 AM
hie there,

i am also confused. ok, i will tell you the redirection of pages. like this :

in institution.php, if already logged in --> reservation.php
if not logged in --> login.php

in login.php, after loggin in, if access level = student, then --> student.php
if not registered --> registration.php
//so in login.php, how can i change the header redirect back to reservation.php because the default redirection is like this

in registration, after register --> login.php to login and continue using the
system

is this clear enough? i hope you can get the idea now. any suggestions, please tell me. really need help on this. thanks alot

davidj
02-06-2007, 08:47 AM
in institution.php, if already logged in --> reservation.php
if not logged in --> login.php


ok first check if the login username $_SESSION is set to determin where to go

call this file loginCheck.php and then include it where you need it at the top of the script

if(isset($_SESSION['username'])){

header("location:reservation.php");

}else{

header("location:login.php");
}

in login.php, after loggin in, if access level = student, then --> student.php
if not registered --> registration.php

you need to set the access level $_SESSION from the login query then its the same as above

in registration, after register --> login.php to login and continue using the
system

and also the same here

remember to write these scripts in a seperate file which you can include in the pages you want it to check on