Forum Moderators: coopster

Message Too Old, No Replies

session history

         

adamnichols45

1:41 pm on Jan 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HEllo i was just wondering what is the easiest way of doing this?

i have a page called 1.php which then has links to either pages called.

3.php
4.php
5.php

problem is on these pages it has a script thats checks if the user is logged in! if they are not they are directed to login.php BUT now when they click sumbit i want them to be taken to the page they orginally selected ie 3,4 or 5 .php

any help is much welcomed. thanks

jatar_k

6:37 pm on Jan 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



grab the referrer or the pagename they requested and pass it along when they get sent to the login form. You could even drop it into the $_SESSION as requested_page or some such var.

adamnichols45

8:45 pm on Jan 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok thanks for that! but how do i grab the pagename that they come from what code would i use for this?

coopster

11:33 am on Jan 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



dmorison laid it out for you in message number 2:

[webmasterworld.com...]

Which part are you stuck on?

adamnichols45

3:34 pm on Jan 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the part of setting the varible and then getting the login page to take it to the previous page!

adamnichols45

6:49 pm on Jan 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this is my login form -

<form action="handle.php" method="POST">
<input type="text" name="username">
<input type="password" name="password">

-----------

handle.php

-------------

<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$_SESSION['username']=$username;
$_SESSION['password']=$password;

// Connect to MySQL

mysql_connect( 'localhost', aaa, 'admin' )
or die ( 'Unable to connect to server.' );

// Select database on MySQL server

mysql_select_db( aa)
or die ( 'Unable to select database.' );

// Formulate the query

$sql = "SELECT * FROM users WHERE
username = '$username' AND
password = '$password'";

// Execute the query and put results in $result

$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );

// Get number of rows in $result.

$num = mysql_numrows( $result );

if ( $num!= 0 ) {

// A matching row was found - the user is authenticated.

$_SESSION['auth']='true';
header("Location: sell.php");

} else {
$_SESSION['auth']='false';
header("Location: login.php");
}

?>
-------------------------------

handle is where i will need to have the redirect to the last visited page.

where will i put the code and can someone tell me what the code should look like please.

thanks

jatar_k

11:20 pm on Jan 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'll tell you what I do.

My login check script is included at the top of every page, I can then use the $_SERVER['REQUEST_URI'] to grab the requested url. Then if they don't pass authentication, since the session is started, I can throw the page into a variable.

$_SESSION['requestedpage'] = $_SERVER['REQUEST_URI'];

then let them login, at the end of your login script

if (isset($_SESSION['requestedpage'])) {
header("Location: " . $_SESSION['requestedpage']);
} else {
header("Location: somepage.php");
}

something along those lines

adamnichols45

9:41 am on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks for all the feedback - the way i done it in the end was like this..

on first page.

$_SESSION['requestedpage']='sell1.php';

on second page

header("Location: " . $_SESSION['requestedpage']);

adamnichols45

7:11 pm on Jan 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi guys i dont think i found an answer for this. rather than starting a new thread.

problem is when the back button is used and the error is Notice: Undefined index: myselect_1 in C:\Inetpub\wwwroot\aa\sells3.php on line 21

i get one of these for most varibles..

the way to sort this is throught what i ask maybe

GET

i dont know can some one let me know please or how about if i disable the back button what is the best action please

jatar_k

10:25 pm on Jan 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



when you hit the back button and go from which page to which page?

adamnichols45

2:54 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



when i go from like page sell4.php back to sell3.php

or sell3.php back to page sell2.php

Adam

jatar_k

5:36 pm on Jan 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I am guessing that the problem is a missing POST param or something like that. I am not really sure what you should do, I never disable browser functionality as a fix, it means the code still has a problem. You will need to check your arrays for the existence of the proper vars and then handle the case that they don't exist.

You could sie the script and then give them a notice that if they use the back button during the process they will have to start over.