Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
<?php session_start(); ?>

<?php 
  $_SESSION['sel_color'] = "blue";
  if ( isset($_GET['color']) ) {

    switch ($_GET['color']) {
      case 'red':
        $_SESSION['sel_color'] = "red";
        break;

      case 'green':
        $_SESSION['sel_color'] = "green";
        break;

      case 'orange':
        $_SESSION['sel_color'] = "orange";
        break;


      default:
        $_SESSION['sel_color'] = "blue";
        break;
    }

  }
  //Let's say this is a draft set session


?>

This is a color changer links

<!--This is color change link to for $_GET['color'] -->
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?color=red">Red</a><br/>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?color=green">Green</a><br/>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?color=orange">Orange</a><br/>

<?php 
  // This is draft print out for which session name is on the page!
  echo $_SESSION['sel_color'];
?>

If I select one color, how do I dynamically add "?color=color_name" to every links on the site. As you know, a site can have hundreds of links, So, how to add "?color="color_name" automatically in every links on the site after I clicked one selected color.! Thanks all.

share|improve this question
1  
I'm not a pro with $_SESSION variables, but isn't the point that you only need to set it once and then it persists? Hence, eliminating the need to have a query variable tacked on to the end of every URL? –  helgatheviking Jul 21 '13 at 20:59
    
Once the session is set it should persist for the duration of the visit. You shouldn't need to tack anything onto the URL. –  s_ha_dum Jul 21 '13 at 22:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.