/    Sign up×
Community /Pin to ProfileBookmark

How do I set a SESSION variable to equal the value of a JavaScript variable?

I need to set some PHP SESSION variables to equal the value in some JavaScript variables. How do I go about doing this?

If I have var jsVariable = “somestring” and $_SESSION[‘phpVariable’], how could I set the latter to equal the former? This has been bothering me for years! ?

Thanks,
Multimediocrity

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiMay 27.2009 — Since PHP is executed server side and javascript is executed (almost always) client side, you will need to send a request to a php script containing the value retrieved via js, using either GET or POST usually. If you need to do this without reloading the whole page you can use AJAX.
Copy linkTweet thisAlerts:
@multimediocrityauthorMay 27.2009 — Thanks. I am not an AJAX wiz, and I haven't used it for a couple years. Even then I didn't fully understand the concepts. Can you recommend me to some code or post it here that would allow me to do this simple transfer of variable data?

I don't mind reloading the page either. I work often with GET and POST. I have about 50 variables that I need to change over (because it's an array). Each variable will probably have about 50 characters. Is there a limit to how much data I can send using GET or POST at one time?

Thanks,

Multimediocrity.
Copy linkTweet thisAlerts:
@themartyMay 28.2009 — I would recommend using a framwork such as jquery
×

Success!

Help @multimediocrity spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...