Jump to content

why dont sessions get "set"? trying to switch to make it works as a breadcrumb..


mac007

Recommended Posts

Hello, all:

 

I have this small script where I am tryign to switch sessions based on what url-variable appears on address, as a way to use like a breadcrumb... and so far it only takes the first one, but then the "category" one doesnt catch... it keeps the "pageNum_worksRS" still active... any ideas?  what am I doing wrong?

 

Thanks!

 

<?php

 

if (isset ($_GET['pageNum_worksRS']))

{

session_start();

$_SESSION['breadcrumb'] = "index.php?pageNum_worksRS=" . $_GET['pageNum_worksRS'];

} elseif (isset ($_GET['category']))

{

session_start();

$_SESSION['breadcrumb'] = "workCategories.php?category=" . $_GET['category'];

}

else { session_start(); }

 

?>

Link to comment
Share on other sites

Because you have "elseif".  Just use and IF statement.  And don't call session_start() three times, just put it at the top of your script.

 

P.S. - Please use


tags, nearly 100 posts, and still don't use them, tisk tisk.

Link to comment
Share on other sites

Try writing it differently:

 

session_start();

if ( isset($_GET['pageNum_worksRS']) )
$breadcrumb = "index.php?pageNum_worksRS=" . $_GET['pageNum_worksRS'];

if ( isset($_GET['category']) )
$breadcrumb = "workCategories.php?category=" . $_GET['category'];

if ( isset($breadcrumb) )
$_SESSION['breadcrumb'] = $breadcrumb;

Link to comment
Share on other sites

OK, I tried rewriting it, but still doenst switch... !??  only the first variable (pageNum_worksRS) gets "read"

 

Seems like it all should work...  but nothing

 

<?php

session_start();
if (isset ($_GET['pageNum_worksRS'])) 
{
$_SESSION['breadcrumb'] = "index.php?pageNum_worksRS=" . $_GET['pageNum_worksRS'];
} 
if (isset ($_GET['category']))
{
$_SESSION['breadcrumb'] = "workCategories.php?category=" . $_GET['category'];
}

?>

Link to comment
Share on other sites

That's not how I'd write it to begin with, but I figured I'd keep it to your style, in case you had a reason for doing so.

 

This is how I'd do it:

<?php

session_register("breadcrumb");

if ( isset($_GET['pageNum_worksRS']) ) 
$breadcrumb = "index.php?pageNum_worksRS=" . $_GET[pageNum_worksRS];

elseif ( isset($_GET['category']) )
$breadcrumb = "workCategories.php?category=" . $_GET[category];

if ( isset($breadcrumb) )
$_SESSION['breadcrumb'] = $breadcrumb;

?>

 

Tested it, and works...

 

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.