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(); }

 

?>

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.

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;

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'];
}

?>

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...

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.