www.webdeveloper.com
Results 1 to 4 of 4

Thread: I need to transfer session varivales into assosiative array

  1. #1
    Join Date
    Nov 2008
    Posts
    18

    I need to transfer session varivales into assosiative array

    I want to transfer following session variables in to associative array. site id is used to each site deferment from each other.

    PHP Code:
    $_SESSION['username_'.$Site_ID]                     = $username;    
    $_SESSION['password_'.$Site_ID]                     = $password;

    $_SESSION['contact_job_title_'.$Site_ID]                     = $contact_job_title;    
    $_SESSION['contact_given_name_'.$Site_ID]             = $contact_given_name;    
    $_SESSION['contact_family_name_'.$Site_ID]            = $contact_family_name;            
    $_SESSION['contact_address_1_'.$Site_ID]             = $contact_address_1;    
    $_SESSION['contact_address_2_'.$Site_ID]             = $contact_address_2;    
    $_SESSION['contact_postcode_'.$Site_ID]             = $contact_postcode;            
    $_SESSION['contact_city_'.$Site_ID]                    = $contact_city;    
    $_SESSION['contact_county_'.$Site_ID]                = $contact_county;    
    $_SESSION['contact_country_id_'.$Site_ID]            = $contact_country_id;    
    $_SESSION['contact_email_'.$Site_ID]                = $contact_email;    
    $_SESSION['contact_telephone_'.$Site_ID]            = $contact_telephone;    
    $_SESSION['contact_mobile_telephone_'.$Site_ID]        = $contact_mobile_telephone;
    $_SESSION['sams_puid_'.$Site_ID]                    = $sams_puid
    Thanks in advance from a new php learner

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,322
    Might I suggest using an additional array dimension? It would probably make things neater for you.
    PHP Code:
    $_SESSION['username'][$Site_ID] = $username;
    // or:
    $_SESSION[$Site_ID]['username'] = $username
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2008
    Posts
    18
    Thanks, I am going to implement this one "$_SESSION['username'][$Site_ID] = $username;" and see how it goes, the reason why i am using is to be able to open more than one website in a browser by keeping there session separate from each other so if i log out from website it will not affect the other site, my present code "$_SESSION['username_'.$Site_ID] = $username; " is working fine but i think it is not professional way to do,
    One thing i need to clarify is "$_SESSION['username']["{$Site_ID}"] = $username; note the " { } " inside the array rather than just the variable is good idea than "$_SESSION['username'][$Site_ID] = $username;" because site_id will be different for every site opened in the browser.

    Many thanks.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,322
    There is no reason in this case to put quotes or curly braces around the $Site_ID variable when being used as an array key. While it will work, all it accomplishes is a tiny bit of extra processing by the PHP parser. In the end, it's still just the variable itself that needs to be parsed.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles