Jump to content

Redirect to a page if logged in.


roldahayes
Go to solution Solved by Ansego,

Recommended Posts

Hi,

 

Can I have some advise on the best way to achieve this task please.

 

I need a way to redirect to a different version of a page once a user enters a specific code.

 

I.e,  The normal page is "basket.php" -  once the user enters the code into a box on that page, it automatically jumps to "basket-trade.php" 

 

The code would need to keep them on the new version of the page everytime they visited the original, until they log out.

 

 

I would need a way to add new codes (That do the same job) for each user that I want this to work for.

 

Any advise would be appreciated,

 

Cheers.

 

 

Link to comment
Share on other sites

  • Solution

Hi,

 

I've not worked with php sessions much, but I am assuming they would be all similar,

 

Maybe something like this:

<?php
if ($_SESSION['mysession'] == 1){
		// REDIRECT
	}else{
		// REDIRECT
	}
?>
Link to comment
Share on other sites

  • 2 weeks later...

Thanks for the advice, this is how I solved it.

 

 

if(isset($_REQUEST['txtLogin'])) 
{ 
session_start();   
$_SESSION['stored_username']=$stored_username; 
} 
 
if(isset($_SESSION['stored_username'])) 
header('Location: basket-trade.php'); 
else 
header('Location: basket.php'); 
 
Link to comment
Share on other sites

Not quite.

 

You must stop the script after the redirect. Otherwise, it will happily keep running, which is a very common security vulnerability.

 

Putting the session_start() into an if statement is also poor practice, because the session will be uninitalized if the condition isn't met. That means every attempt of accessing $_SESSION will throw a notice.

 

Last but not least, get rid of the $_REQUEST variable and properly fetch the data from either the URL ($_GET) or the request body ($_POST).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.