Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-05-06 09:20:05
Point:500 Replies:12 POST_ID:828550USER_ID:11059
Topic:
PHP Scripting Language;JavaScript;Linux
I read most articles or blogs from google search to find out where is
the session or session variable in php to be saved, most blogs or forums said
the session/session variable is saved on the server. For example , following link
http://stackoverflow.com/questions/454635/where-are-session-variables-stored.
But I don't why it is saved on server ? So I go to do a simple php test
Make a test php file and name it as test.php with the following simple code
the session or session variable in php to be saved, most blogs or forums said
the session/session variable is saved on the server. For example , following link
http://stackoverflow.com/questions/454635/where-are-session-variables-stored.
But I don't why it is saved on server ? So I go to do a simple php test
Make a test php file and name it as test.php with the following simple code
<?phpsession_start();$_SESSION['SESS_MEMBER_ID']="testing";$_SESSION['SESS_FIRST_NAME']="firstpccw";echo $_SESSION['SESS_MEMBER_ID'];echo $_SESSION['SESS_FIRST_NAME'];?> 1:2:3:4:5:6:7:
and make second.php with the following simple code that just echo variable (not set)
<"?phpsession_start();"echo $_SESSION['SESS_MEMBER_ID'];"echo $_SESSION['SESS_FIRST_NAME'];"?>" 1:2:3:4:5:
And I run test.php on my IE browser such as http://www.,mysite.com/test.php
it set and echo those two session variables on my IE browser finally. So it is fine.
If the session variables is saved in my server, I should be able to read the variable on other computer and , so I run the second.php script on IE such as http://www.mysite.com/second.php on other computer . but it doesn't echo out those two variabels on IE on other computer. Why ? BE reminded, I have two different PC computer and two telephone lines
SO I get confused ! Please advise why second.php doesn't echo out /display the variable
on IE on other computer ?
OR the reason is running php script on window computer browser, the variable is
saved on the client browser, is it right ?
If on linux server running the php script at Linux shell , the variable, of course, must save on the server, is that people are talking about ?
Please help on my confusion about where the session variable is saved
Duncan
Assisted Solution
Expert: Dave Baldwin replied at 2024-05-06 11:59:18
72 points GOOD
No, 'session cookies' expire when you close the browser, not just the window but the whole browser. While that does not instantly expire the session on the server, you will not get the same session back if you immediately start up your browser and go back to the site.
Session cookies do not have an expiration date which is how the browser knows to delete them when it closes. Changing the expiration time as shown above is not recommended because it allows the cookie to persist until the next time the browser is opened. And in situations where more than one person uses the computer under the same account, that will allow that next person access to your session.
Session cookies do not have an expiration date which is how the browser knows to delete them when it closes. Changing the expiration time as shown above is not recommended because it allows the cookie to persist until the next time the browser is opened. And in situations where more than one person uses the computer under the same account, that will allow that next person access to your session.
Assisted Solution
Expert: brucepieterse replied at 2024-05-06 11:44:42
71 points GOOD
After re-reading your initial post, I think you want a solution where:
A user at computer 1 logs in. Adds product A to a shopping cart.
User at computer 1 decides to use their laptop (computer 2).
At computer 2, the user logs in and can see Product A in the shopping cart.
Is that what you referring to? I'm only taking a guess here because you have not provided us with more information on what exactly you are trying to achieve/build. If the above is something along the lines that you want to get done and answers your question then you need to look at storing sessions in a database:
https://sammaye.wordpress.com/2009/11/09/php-database-sessions/
http://stackoverflow.com/questions/2045194/should-i-use-database-sessions-or-native-php-file-sessions#2045264
A user at computer 1 logs in. Adds product A to a shopping cart.
User at computer 1 decides to use their laptop (computer 2).
At computer 2, the user logs in and can see Product A in the shopping cart.
Is that what you referring to? I'm only taking a guess here because you have not provided us with more information on what exactly you are trying to achieve/build. If the above is something along the lines that you want to get done and answers your question then you need to look at storing sessions in a database:
https://sammaye.wordpress.com/2009/11/09/php-database-sessions/
http://stackoverflow.com/questions/2045194/should-i-use-database-sessions-or-native-php-file-sessions#2045264
Expert: brucepieterse replied at 2024-05-06 11:26:55
That's correct. You can extend the session lifetime with session_set_cookie_params() function. I have attached a snippet of a custom session_start() function:
define("INSTALLATION_NAME","My_App");define("SERVER", "localhost");define("PATH","/");function start_session() { session_name(INSTALLATION_NAME); session_set_cookie_params(3600,PATH,SERVER,FALSE,TRUE); session_start(); if($_SESSION['remember_me'] == 'Y') { define('COOKIE_TIMEOUT', 3600 * 24 * 30); } elseif($_SESSION['remember_me'] == 'N') { define('COOKIE_TIMEOUT', 3600); } else { define('COOKIE_TIMEOUT', 3600); } if(isset($_COOKIE[INSTALLATION_NAME])) { setcookie(INSTALLATION_NAME, session_id(), time() + COOKIE_TIMEOUT, PATH,SERVER,FALSE,TRUE); }} 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:
If a user sets the "Remember me" option before submitting the login details, we create the lifetime of the cookie to be 30 days otherwise 1 hour if they have not checked "Remember Me". The last portion checks to ensure that a cookie is set called My_App, and if it is set, we update the lifetime of that cookie.
Author: duncanb7 replied at 2024-05-06 11:11:28
It might eb short, that is why people are using session cookie to save
the info on client browser to set expired time to any time, RIght ?
the info on client browser to set expired time to any time, RIght ?
Accepted Solution
Expert: Dave Baldwin replied at 2024-05-06 10:49:36
71 points GOOD
Right, you can't get the session variable stored by another user even though it has the same name because the data for each user is stored separately.
The default session time-out is 1440 seconds (24 minutes) of inactivity. Each page you access during a session resets the timer to 1440 seconds. It can be changed and a session can be canceled.
The default session time-out is 1440 seconds (24 minutes) of inactivity. Each page you access during a session resets the timer to 1440 seconds. It can be changed and a session can be canceled.
Author: duncanb7 replied at 2024-05-06 10:47:56
Probably, I am closing to understand the session meaning now
Author: duncanb7 replied at 2024-05-06 10:42:43
I try echo SID on different computer, they echo different PHPSESSID such as
testingfirstpccwPHPSESSID=7a33385aad5749709b250e155d73e980,
SO it is session id , RIght ? and it is different when the browser is quit and re-open
and it is changing from time or from different computer.
So in other words, I can not get session variable value from other computer is doing seesion even the variable name is same in php script. ?
Do you know how long the session varialbe can be expired, one minuste or 20 minute
on the same browser ?
Please advise
Duncan
testingfirstpccwPHPSESSID=7a33385aad5749709b250e155d73e980,
SO it is session id , RIght ? and it is different when the browser is quit and re-open
and it is changing from time or from different computer.
So in other words, I can not get session variable value from other computer is doing seesion even the variable name is same in php script. ?
Do you know how long the session varialbe can be expired, one minuste or 20 minute
on the same browser ?
Please advise
Duncan
Assisted Solution
Expert: Dave Baldwin replied at 2024-05-06 10:35:46
71 points GOOD
Session variables are saved on the server under the session id for each session. Even though you see the same name like $_SESSION['SESS_MEMBER_ID'] in your code, it is actually different for each and every session. The idea is that each user's session is isolated from every other user so you can temporarily store info about that user in their session without giving it away to another user. These pages http://us3.php.net/manual/en/book.session.php tell all about sessions.
Assisted Solution
Expert: brucepieterse replied at 2024-05-06 10:04:10
71 points GOOD
Hi
You can also compare the session string by simply echoing SID in your scripts.
You can also compare the session string by simply echoing SID in your scripts.
<?phpsession_start();$_SESSION['test'] = "hello<br>";echo $_SESSION['test'];echo SID; 1:2:3:4:5:
Author: duncanb7 replied at 2024-05-06 10:03:54
Just want to understand the concept of session and where is session variable saved
You mean, if I run test.php(set and read varaible) on two different computer, the
variable $_SESSION['SESS_MEMBER_ID'] is diffferent and this is two different variable name
with the same value(By $_SESSION['SESS_MEMBER_ID']="testing";) saving my server even it is same variable name runnng on different computer, RIght ?
Duncan
You mean, if I run test.php(set and read varaible) on two different computer, the
variable $_SESSION['SESS_MEMBER_ID'] is diffferent and this is two different variable name
with the same value(By $_SESSION['SESS_MEMBER_ID']="testing";) saving my server even it is same variable name runnng on different computer, RIght ?
Duncan
Assisted Solution
Expert: stevepwales replied at 2024-05-06 09:39:57
72 points GOOD
session vars are unique to the user u will not be able to see session vars from1 session on another session. They are stored in the server the location is set in you php config file
Assisted Solution
Expert: Dave Baldwin replied at 2024-05-06 09:34:07
72 points GOOD
No, you should not be able to see it on the second computer. Each computer will cause a different session to be started. For security purposes, info is Not shared between sessions. You don't want someone else to be seeing your info.
If you want info to be shared between users, you should put it in a database. Sessions are not going to do it for you. Read all about sessions. They are not quite as simple as you are trying to make them. http://us3.php.net/manual/en/book.session.php
If you want info to be shared between users, you should put it in a database. Sessions are not going to do it for you. Read all about sessions. They are not quite as simple as you are trying to make them. http://us3.php.net/manual/en/book.session.php