mac007 Posted April 23, 2009 Share Posted April 23, 2009 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 https://forums.phpfreaks.com/topic/155299-why-dont-sessions-get-set-trying-to-switch-to-make-it-works-as-a-breadcrumb/ Share on other sites More sharing options...
Maq Posted April 23, 2009 Share Posted April 23, 2009 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 https://forums.phpfreaks.com/topic/155299-why-dont-sessions-get-set-trying-to-switch-to-make-it-works-as-a-breadcrumb/#findComment-817038 Share on other sites More sharing options...
alphanumetrix Posted April 23, 2009 Share Posted April 23, 2009 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 https://forums.phpfreaks.com/topic/155299-why-dont-sessions-get-set-trying-to-switch-to-make-it-works-as-a-breadcrumb/#findComment-817040 Share on other sites More sharing options...
mac007 Posted April 23, 2009 Author Share Posted April 23, 2009 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 https://forums.phpfreaks.com/topic/155299-why-dont-sessions-get-set-trying-to-switch-to-make-it-works-as-a-breadcrumb/#findComment-817044 Share on other sites More sharing options...
alphanumetrix Posted April 23, 2009 Share Posted April 23, 2009 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 https://forums.phpfreaks.com/topic/155299-why-dont-sessions-get-set-trying-to-switch-to-make-it-works-as-a-breadcrumb/#findComment-817068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.