1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

session

Discussion in 'PHP' started by chxxangie, Nov 25, 2008.

  1. #1
    
    $cardtype = @$_GET['type'];
    $_SESSION['cardtype'] = $cardtype;
    
    PHP:
    
    $cardtype = @$_GET['type'];
    if($cardtype=="new"){	
    	$_SESSION['cardtype'] = "new";
    }
    if($cardtype=="replace"){	
    	$_SESSION['cardtype'] = "replace";
    }
    if($cardtype=="create"){	
    	$_SESSION['cardtype'] = "create";
    } 
    
    PHP:
    why the session in first code cannot hold the value of $cardtype.
    when i try to change the code to the second code, then the session can hold the value of $cardtype to the following page. it is weird.
    i wonder why the first code cannot display the value? it should be can be displayed.
     
    chxxangie, Nov 25, 2008 IP
  2. GreatMetro

    GreatMetro Peon

    Messages:
    117
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Make sure you start with session_start();
     
    GreatMetro, Nov 25, 2008 IP
  3. chxxangie

    chxxangie Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes, i do insert the session_start();
     
    chxxangie, Nov 25, 2008 IP
  4. share_boy

    share_boy Active Member

    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    If the PHP directive register_globals is set to on then session values will also be made into variables. try to change different name for session.

    example :

    $_session[ctype] = $cardtype;
     
    share_boy, Nov 25, 2008 IP
  5. chxxangie

    chxxangie Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    doesn't work too :(
     
    chxxangie, Nov 26, 2008 IP
  6. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ok the reason is that on the first code the session variable is set to blank if you go to that page and $_GET['type'] is not set . where as the second one if its not set to something specific it doesnt write to the session variable
     
    atlantaazfinest, Nov 26, 2008 IP
  7. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #7
    Make sure you have the value in $_GET['type'] and remove @ before this line.
     
    mwasif, Nov 26, 2008 IP