Advertisement

04.18.2008 at 01:32AM PDT, ID: 23333519
[x]
Attachment Details

Passing JavaScript Variable to PHP Session variable

Asked by davenixon981 in PHP Scripting Language, CGI Scripting, PHP and Databases

Tags: PHP JavaScript, IE7, Firefox, Opera

I found what I was looking for, in an old thread (ID 11448788 posted by rockmansattic July 5, 2004) I do not want to set urls I want to pass the JavaScript variable straight into a PHP Session variable
 
<SCRIPT LANGUAGE='JavaScript'>
<!-- //
var name="Dave";
var number=100;

It is around here I get totally confused (if you could give me some detailed examples for newbies, I'd really appreciate it) Below is what I think I should be doing

document.write(<?php $var1 = $_GET['name']; $var2= $_GET['number']; ?>)
</script></head><body>
<?PHP  $_SESSION['var1'] = $var1; $_SESSION['var2'] = $var2'] ?>
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
rockmansattic:
You can do it by setting url variables or session variables.  
one way to do this is to pass the url like this
 
<SCRIPT LANGUAGE='JavaScript'>
<!-- //
var name="Dave";
var number=100;
document.write('<a href="another_page.php?name='+name+'&number='+number+'">another page</a>');
// -->
</SCRIPT>
 
 
<?php $var1 = $_GET['name']; $var2= $_GET['number']; ?>
 
you can do this via GET, POST, SESSION
 
You could do this all on the same page if you wanted to by calling a javascript function that sets these variables and then php gets them.
 
Let me know if you need more code.
 Rockman
Attachments:
 
Get JavaScript Variable into PHP Session variable
 
[+][-]04.18.2008 at 01:39AM PDT, ID: 21384076

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, CGI Scripting, PHP and Databases
Tags: PHP JavaScript, IE7, Firefox, Opera
Sign Up Now!
Solution Provided By: paulop1975
Participating Experts: 2
Solution Grade: B
 
 
[+][-]04.18.2008 at 01:41AM PDT, ID: 21384084

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 02:36AM PDT, ID: 21399801

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628