WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
<?php session_start(); ?>

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

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

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

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

        $_SESSION['sel_color'] = "blue";

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

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


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

Browse other questions tagged or ask your own question.