SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    A simple question about variables

    I've changed the way I've done my website, over time, and I've had to include each of these in my header.php file to capture the same thing. Each of these is capturing a referral number in the URL, if there is one:

    $x = $_REQUEST['x'];
    $sponsor = $_REQUEST['sponsor'];
    $source = $_REQUEST['source'];

    To make things less complex elsewhere in the code, how can I change this code so no matter which format is found, it will use $sponsor ? Can I just change it to this?

    $sponsor = $_REQUEST['x'];
    $sponsor = $_REQUEST['sponsor'];
    $sponsor = $_REQUEST['source'];

    That way, no matter if x, sponsor, or source is supplied in the URL, it will be stored as sponsor. Right?

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    Grumpy Minimalist
    Join Date
    Jul 2006
    Location
    Ontario, Canada
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $sponsor null;
    if (isset(
    $_REQUEST['sponsor'])) $sponsor $_REQUEST['sponsor'];
    elseif (isset(
    $_REQUEST['x'])) $sponsor $_REQUEST['x'];
    elseif (isset(
    $_REQUEST['source'])) $sponsor $_REQUEST['source'];
    else { 
    /*Do something here when no sponsor is specified.*/ 
    This will load $sponsor with the value from one of the three parameters, in order of precedence: sponsor, x, source. If none of these are set, $sponsor will be null, and the code will branch to the comment (replace this comment with some sort of error handling if needed).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •