Jump to content

Better way to say "Don't go to these pages"


doubledee

Recommended Posts

When a User logs out, I redirect them like this...

 

if (isset($_SESSION['returnToPage']) && ($_SESSION['returnToPage'] != 'members/my_account.php')){
	$returnToPage = $_SESSION['returnToPage'];
}else{
	$returnToPage = "/index.php";
}

 

In English I am saying, "If you were just on the My Account page, go to the Home Page because the returnToPage could have been something else that would confuse you if you went back there?!"

 

Now I want to do the same thing for 6 other pages related to My Account.

 

Is there an efficient way to do that versus a really ugly IF-THEN-ELSE??

 

Thanks,

 

 

Debbie

 

Link to comment
Share on other sites

So, why not just use..

 

if($_SESSION['loggedOut']) == true) {
  $returnToPage = "/index.php";}
}else {
  $returnToPage = $_SESSION['returnToPage'];
}

..on each page?

 

I could, but I'm thinking it might be more complicated since on each page it is possible (?) to have different $returnToPages based on the logic of the page.

 

(At this late stage I don't wanna muck with that variable.)

 

I figured it would be easier to say, "If you are on any of these 6 pages, then ignore the $returnToPage and go to the index.php page."

 

 

Debbie

 

Link to comment
Share on other sites

why not use a switch for  $_SESSION['returnToPage'']

 

 

then you could use the case to pass your arguments in.

 

switch($_SESSION['ReturnToPage']){

case($_SESSION['ReturnToPage']=='allowedfile1'):
$returntopage=$_SESSION['ReturnToPage'];
//do the same for all pages you want allowed.
break;
}
echo $returntopage;

Link to comment
Share on other sites

Does $_SESSION['returnToPage'] simply hold the http_referer?

 

A switch is the way to go for this I believe, to compare multiple values against the session value.

darkfreaks was close, however the switch syntax is a little off:

 

$returnToPage = null;
switch($_SESSION['returnToPage'])
{
    case 'members/my_account.php':
        $returnToPage = '/index.php';
        break;
    default:
        $returnToPage = $_SESSION['returnToPage'];
        break;
}

 

You will add new cases for each referer that you do not want to set $returnToPage to the session value.

The default condition will trigger if the session value does not equal any case values.

You can (should?) add the switch into an if statement checking for the session being set first.

Link to comment
Share on other sites

Does $_SESSION['returnToPage'] simply hold the http_referer?

 

A switch is the way to go for this I believe, to compare multiple values against the session value.

darkfreaks was close, however the switch syntax is a little off:

 

$returnToPage = null;
switch($_SESSION['returnToPage'])
{
    case 'members/my_account.php':
        $returnToPage = '/index.php';
        break;
    default:
        $returnToPage = $_SESSION['returnToPage'];
        break;
}

 

You will add new cases for each referer that you do not want to set $returnToPage to the session value.

The default condition will trigger if the session value does not equal any case values.

You can (should?) add the switch into an if statement checking for the session being set first.

 

I need to re-think how I'm doing this, but your suggestion has merits!

 

Thanks,

 

 

Debbie

 

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.