homepage Welcome to WebmasterWorld Guest from 54.166.96.101
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Altering a PHP $ Session var via Javascript?
Can it be done?
neophyte

10+ Year Member



 
Msg#: 3573535 posted 4:52 am on Feb 13, 2008 (gmt 0)

Hello All -

I've got a scenario where I would like to alter a PHP $_SESSION array via Javascript. It's like this:

1. PHP page is displayed containing a number of form elements for a person's name, position, hair color, etc.

2. During page display, a PHP $_SESSION array is set: $_SESSION['TSets'] = array('RegInfo');

One of the form elements on this page is a checkbox. When the checkbox is clicked a fieldset is shown via Javascript.

Now IF this checkbox is clicked, I need to alter the $_SESSION array shown above from $_SESSION['TSets'] = array('RegInfo'); to $_SESSION['TSets'] = array('RegInfo','CreditCard');

Conversely, if someone has already clicked the check box, then changes their mind and un-clicks it, I need to once again alter the session from $_SESSION['TSets'] = array('RegInfo','CreditCard'); back to simply $_SESSION['TSets'] = array('RegInfo');

Now I know that PHP is server-side and Javascript is client-side, but since PHP sessions are persistant, I don't see why (theoretically) Javascript couldn't alter a PHP Session VAR or a session Array.

So, since I don't know how to code in Javascript my question is: A) can this be done, and B) if it can, would someone show me a little code snippet on how this can be accomplished?

Thanks to all in advance,

Neophyte

 

Tastatura

5+ Year Member



 
Msg#: 3573535 posted 5:50 am on Feb 13, 2008 (gmt 0)

I am not an expert in JS so take this with grain of salt....How are you handling session info - storing it in the cookie or propagating in in URL? I know that cookie data written by PHP can be read by JavaScript ( and vice versa) [might need page reload or user to go to 'next' page in order to read data]. Same goes for query part of the url (everything after www.example.com/mypage? ...) - both languages can parse it out. Or there might be some slick AJAX ( JS) approach but again I am not an expert. Quick search on any SE for reading cookie or query string in JS will give plenty tutorial examples.

HTH

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved