1

I have a simple web page that has 3 tabs in my main content area. Once a user clicks on a particular tab, I use jquery and ajax to fetch some data from server and (of course) without reloading everything I change some div below those three tabs.

I use $.post to get data from the server and there are 3 different php files on a server that I call (one for each tab) and get data from.

Is it possible to start a php session when a user clicks on the first tab and save some $_SESSION variables and then use them when a user clicks on the second or third tab so that I know what user clicked on the second or third tab?

Thanks! Newman

Newman
  • 27
  • 6

1 Answers1

1

Yes, the sessions are shared across all php scripts. So whatever you save in the first tab will be readable on 2nd and 3rd tab. Keep in mind that

Edit: Thing to keep in mind here is that the domain should remain the same for all scripts to be able to see the session.

Sabeen Malik
  • 10,816
  • 4
  • 33
  • 50
  • Well, what I actually want is to store data that I get in php (trough shell_exec) and save it in $_SESSION array and display in other tabs. Is this possible? – Newman Apr 11 '11 at 16:52
  • i am not sure about the relevance of shell_exec here , prolly you can share your code? – Sabeen Malik Apr 11 '11 at 16:54
  • Well, I wan to do something as simple as this: $_SESSION[mac]=shell_exec('ifconfig | awk '/eth0/ {print $5}' '); and then use this variable for something in other tabs. – Newman Apr 11 '11 at 16:56
  • well sure .. i can not guarantee if you would get any output from your shell_exec command, but if you do it should save perfectly in the session var and should be accessible in other tabs. If you are having issues make sure your shell_exec command returns valid output. Also make sure all tab scripts have session_start at the top of the script. – Sabeen Malik Apr 11 '11 at 17:00
  • I know, I just wrote that from my head, syntax is definitely wrong :) But I was just wondering will this work just by using session_start() on in every php file. How is than session identified for different users? – Newman Apr 11 '11 at 17:02
  • Each session is stored in a separate file on the server. To identify different users a cookie is set into the browser. So each file on the server corresponds to a different user. All of the session data is stored in the files on the server and the cookie just acts as the identifier. – Sabeen Malik Apr 11 '11 at 17:06
  • So if a cookies are off in a browser, this can't work? And I thought that cookies need to be created manually from php...I'm really new to sessions in php, so forgive my ignorance. And thanks!!! – Newman Apr 11 '11 at 17:09
  • Its aright, we all got to start somewhere :) Hopefully this question will answer your question http://stackoverflow.com/questions/613967/how-do-php-sessions-work-when-cookies-are-disabled – Sabeen Malik Apr 11 '11 at 17:11