Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2013
    Location
    Allen, TX
    Posts
    34
    Plugin Contributions
    0

    Default How do I create my own session variable?

    In the header_php.php for a new page I am trying to create a new session variable such as $_SESSION['New_Var'] = 'New Var'; However, when the page redirects to header('Location:....); When I print the session there is no new variable. How do I add the new variable?

    Blessings,
    Tiffany

  2. #2
    Join Date
    Apr 2013
    Location
    Allen, TX
    Posts
    34
    Plugin Contributions
    0

    Default Re: How do I create my own session variable?

    Never mind I got it...I just needed to start_session()

  3. #3
    Join Date
    Apr 2013
    Location
    Allen, TX
    Posts
    34
    Plugin Contributions
    0

    Default Re: How do I create my own session variable?

    Well if I add start_session() then I am able to save my own variable but then the other variables are lost. How do I create new variables without deleting the old variables?
    Last edited by tifischer; 6 Aug 2016 at 08:42 PM. Reason: typo

  4. #4
    Join Date
    Jul 2012
    Posts
    16,095
    Plugin Contributions
    17

    Default Re: How do I create my own session variable?

    Umm. Provided $_SESSION['new_var'] exists before something prevents it from being set (redirect beforehand or perhaps a logout) the doing like:
    Code:
    $_SESSION['new_var'] = 'test this';
    will set the session variable. Be sure that you have the underscore and everything else about the line is properly formatted. Otherwise you may need to post your code in order to figure out what is going wrong because I frequently will use that type of assignment so that results can be immediately seen without affecting page display, loading extra files/folders, or affecting program flow.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Jan 2004
    Posts
    66,350
    Blog Entries
    7
    Plugin Contributions
    271

    Default Re: How do I create my own session variable?

    Ya, more info needed (code is ideal) about what you're doing in the header_php.php file, and otherwise. The session should already be started by the time execution gets to that page .... unless you're getting there by some unconventional means.

    Too little context here to actually help you effectively.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Apr 2013
    Location
    Allen, TX
    Posts
    34
    Plugin Contributions
    0

    Default Re: How do I create my own session variable?

    Quote Originally Posted by DrByte View Post
    Ya, more info needed (code is ideal) about what you're doing in the header_php.php file, and otherwise. The session should already be started by the time execution gets to that page .... unless you're getting there by some unconventional means.

    Too little context here to actually help you effectively.
    The new session is like $_SESSION['SCHOOL_NAME'] = base64_encode($some."|".$school."|".$info);

    If I remove the session_start in the header_php.php file for the page, and then print_r the session, then I get the session name added but not the value when the new page loads. A print_r on $_session returns:
    ... [language] => english [SCHOOL_NAME] => [securityToken] => 07842b9f0fda02a832dfdfe7f5a04633

  7. #7
    Join Date
    Jul 2012
    Posts
    16,095
    Plugin Contributions
    17

    Default Re: How do I create my own session variable?

    Is the key SCHOOL_NAME as written all caps? Is there a define somewhere in your code for the constant SCHOOL_NAME? I thought there was some "check" performed to prevent a session from overwriting a constant or some relationship with a $_GET or $_POST. There's some code in includes/init_includes/init_sanitize.php that addresses what I was thinking about but I don't know how it plays with what you are observing, other than I don't typically use all uppercase letters for something that is not to be a constant though that doesn't necessarily make the expression a constant.

    See thing is, the "variable" is being created, but it's (expected) contents are not transferring or at the point of observation have been modified. Have you tried backing out to first just content not yet encoded? Does it act differently? Have you tried appending some "constant" to the 'SCHOOL_NAME' such that it would be seen as a different variable from page load to page load but could be referenced as necessary/desired?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #8
    Join Date
    Apr 2013
    Location
    Allen, TX
    Posts
    34
    Plugin Contributions
    0

    Default Re: How do I create my own session variable?

    Quote Originally Posted by mc12345678 View Post
    Is the key SCHOOL_NAME as written all caps? Is there a define somewhere in your code for the constant SCHOOL_NAME? I thought there was some "check" performed to prevent a session from overwriting a constant or some relationship with a $_GET or $_POST. There's some code in includes/init_includes/init_sanitize.php that addresses what I was thinking about but I don't know how it plays with what you are observing, other than I don't typically use all uppercase letters for something that is not to be a constant though that doesn't necessarily make the expression a constant.

    See thing is, the "variable" is being created, but it's (expected) contents are not transferring or at the point of observation have been modified. Have you tried backing out to first just content not yet encoded? Does it act differently? Have you tried appending some "constant" to the 'SCHOOL_NAME' such that it would be seen as a different variable from page load to page load but could be referenced as necessary/desired?
    It just happens that I abbreviate the school names so that the school names happen to be in caps, there are no interfering definitions.

  9. #9
    Join Date
    Jan 2004
    Posts
    66,350
    Blog Entries
    7
    Plugin Contributions
    271

    Default Re: How do I create my own session variable?

    In original core ZC code, any of the files under /includes/modules/ are called only after the session is started, so setting a value in one of those files should allow you to read that same value during subsequent visits using that same session.

    If the value is set to an empty string, then (as mc8 mentioned above) clearly it's being set so your code is creating the entry, but then something in your own code is resetting it to empty.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. v154 Naming a global variable the same as a SESSION, GET or POST variable
    By torvista in forum General Questions
    Replies: 5
    Last Post: 6 Dec 2015, 11:11 AM
  2. v150 how can i add session variable with it file path ?
    By tony_sar in forum General Questions
    Replies: 3
    Last Post: 14 Feb 2012, 01:50 PM
  3. how to add a new session variable?
    By delia in forum General Questions
    Replies: 11
    Last Post: 13 Oct 2011, 02:51 PM
  4. I want to set my own cookie or session variable
    By rweeks in forum General Questions
    Replies: 7
    Last Post: 20 Feb 2010, 11:44 AM
  5. How do i add a new session variable?
    By rosebabu in forum General Questions
    Replies: 0
    Last Post: 7 May 2008, 03:03 PM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR