473,804 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

variables in javascript or as $_SESSION?

21 New Member
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 1517
acoder
16,027 Recognized Expert Moderator MVP
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
3947
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 function. I prepared an example that can demonstrate the problem (see code bellow): The program flow is this: (1) It starts with "session_start()" and displays "login_form()". (2) When user enters his username and password, it goes to "login()"
1
2331
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. This selected data gets passed internally using session variables to the next page. This page takes the passed data, runs it for error checking and determines where to send it next. I have gotten most of the desired results through this method...
7
2040
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
3130
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 program. is this a valid concern? i'm thinking i can check the submitting page setting up something around the following the following code... $base_name = basename($_SERVER);
7
2046
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 to a new page the upload will not work. despite the variables being set. I have echoed then on the second page and they display correctly but they just dont work in the move_uploaded_file() function. I get the error message Error uploading...
0
1482
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 number. that in turn goes to the next page where its being picked up by the php code and put into the Global Variable. the page uses the variables with no problem and you can select a link to go onto the next page where the number is being...
22
14909
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 done in 3 steps: Step 1. Normal http login page. Step 2. A page called login.php that takes the posted username, stores it as $_SESSION, and registers it session_register("username"); user is taken to the personalized page according to his username...
8
3027
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, successfully authenticating against Active Directory, I send them from the login.php page to the index.php page. But when I get to the index.php page, the session ID is visible, but the session variables and values are not. Can you help me out? Also,...
10
313
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. If I comment out the include of menu1.php, then homepage.php sees the session variables. I have done this with and without session_start() in menu1.php. I can't see why it would lose the session variables. tmpl.php: ========= <?php include...
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.