473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

variables in javascript or as $_SESSION?

21
Hi I'm trying to use $_SESSION in my AJAX application.
However this gives me strange data, the $_SESSION variable seems to
change during page load. in the end of the page it's the earlier value that shows.

I set the $_SESSION[id] with this
Expand|Select|Wrap|Line Numbers
  1. function setId(id)
  2. {
  3.     try{
  4.     var obj;
  5.     obj  = document.getElementById("sid");
  6.     var serverPage = "setid.php" + "?id="+id;
  7.     xmlhttp.open("GET",serverPage);
  8.     xmlhttp.onreadystatechange = function(){
  9.         if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
  10.             obj.value = xmlhttp.responseText;
  11.         }
  12.     }
  13.         xmlhttp.send(null);
  14.     }catch(eeex)
  15.     {
  16.         alert(eeex);
  17.     }
  18. }
  19.  
So if I don't use $_SESSION the user will loose the id when reloading. I'm just wondering if I'm totally wrong with trying to use $_SESSION

this code below prints out value x the first time, and when $ss it's the old value
meaning $ss != $_SESSION[''id], and the reason I'm using $ss is because otherwise it's empty.

Expand|Select|Wrap|Line Numbers
  1.     <input id="tId" name="Id" type="hidden" value="<?php $ss = $_SESSION['id'];echo $_SESSION['id'];?>" />
  2.  
  3.       <input type="submit" name="Submit" value="Save" onclick="submitform(document.getElementById('newproj'),
  4. 'process_cons_projects.php','cons_proj_message',validatetask);
  5. updateprojectlist('<?php echo $ss; ?>');return false;"/>
  6.     </label></td>
  7.  
Mar 14 '07 #1
1 1483
acoder
16,027 Expert Mod 8TB
The session value is set server-side (PHP).
Mar 1 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Pavel Vetesnik | last post by:
Greetings! I have some troubles with session variables. I can easily create a session, but the variable I append to global session array ( $_SESSION) lasts only until the end of current...
1
by: z0ink | last post by:
I am working on a small graphing application. In the process of graphing I use 3 seperate scripts for getting the job done. The first is the page that the use sees and selects all the data from. ...
7
by: Nicole | last post by:
Hi I'm trying to use a function to set a session variable. I have three files: The first file has: <?php session_start(); // This connects to the existing session ?> <html> <head>
28
by: Skeets | last post by:
i'm passing session and hidden variables between pages. not to mention post values. i'm a little concerned that someone with sufficient knowledge could spoof these vlaues and manipulate the...
7
by: mantrid | last post by:
I have some code to upload files to my site. it works when the <input type="file" is posted once even when I use session variables from the posted variables but when I carry those session variables...
0
by: Aarchaic | last post by:
Hello i have problem my session variables seem to disapear as i go along i've created this code to ilustrate whats happening First off i just post 3 detials like a name a age and a favourite...
22
by: K. A. | last post by:
I have two servers at work, 'A' for testing and development, and server 'B' for production. On server A, I wrote a PHP test code to login users then direct them to a personalized page. This is...
8
by: Eddie | last post by:
I am having difficulty in setting variables in a session, and then accessing those variables throughout the web pages that they click on. After having them set a user name and password,...
10
by: sheldonlg | last post by:
Something weird is happening here. I inherited some code that looks like what is shown below. The problem is that when menu1.php is included, the session variables are not known in homepage.php. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.