Hi guys,
What is the best method to return a user to the page they where on after they have logged in?
Thanks all.
Regards Paul
Best method to return user after they login.
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Best method to return user after they login.
Well, you can try redirecting back to $_SERVER['HTTP_REFERER'] but that isn't always set. So on each page in your site (except the login page) you can set a session var for the current page. Then on the login page you have that var that was set on the previous page.
-Shawn
-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Best method to return user after they login.
That only works if cookies & sessions are being used. I've seen some login pages that have "&return=/page/from/whence/the/user/came" in the URL. The login page can then read that from $_GET & redirect the user back.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Best method to return user after they login.
Good luck logging people in and maintaining some sort of state to tell if people are logged in or not without using sessionspickle wrote:That only works if cookies & sessions are being used. I've seen some login pages that have "&return=/page/from/whence/the/user/came" in the URL. The login page can then read that from $_GET & redirect the user back.
Well, I guess you could append their username or id and a strong hash of their password (assuming the same hash is stored in the DB or whatever) to every link and form action, etc...on every page in your site/app after they log in, but that would be ridiculous!
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Best method to return user after they login.
Thanks for the advice guys. This is what I have come up with.
I have used this little function I found after some googling.
I saved it as getURL.php and included it in my page...
I then declared a variable from the function and then set it as a session so it can be picked back up as required.....
Do you think this is okay or is there a better way.
Regards, Paul
I have used this little function I found after some googling.
Code: Select all
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>Code: Select all
include("getURL.php");Code: Select all
session_start();
$returnURL = curPageURL();
$_SESSION['returnURL'] = $returnURL;Regards, Paul
Last bumped by tuxiow on Mon Dec 07, 2009 3:21 pm.