0

For example, I start a session on index.php which has my form. In my form I have a name input and a submit button. I create this code:

$_SESSION['name'] = $_POST['name'];
header('Location: page.php');

On page.php I start the session and display the message

 <h3>Thank you <?php echo $_SESSION['name'];?>, for signing up.</h3>

How is that posted name data passed to page.php?

  • Data is serialized and stored in the server. – Spoody Apr 29 '18 at 14:30
  • Possible duplicate of [How do PHP sessions work? (not "how are they used?")](https://stackoverflow.com/questions/1535697/how-do-php-sessions-work-not-how-are-they-used) – Spoody Apr 29 '18 at 14:30

1 Answers1

1

In the context of http, sessions are a way of passing data between pages/requests as http is stateless.

How does the page know of the values in your example? Because they are stored in session variables and available through the request.

For background see: https://www.w3schools.com/php/php_sessions.asp

What is session and session variables?

http://php.net/manual/en/reserved.variables.session.php

https://en.m.wikipedia.org/wiki/Session_(computer_science)#Web_server_session_management

salah-1
  • 1,299
  • 11
  • 15
  • So in my case the session does not really have much to do with it. The posted name from the input is what gets carried over to the next page where I can store that post data to a session variable. – Garrett Rose Apr 29 '18 at 14:51
  • Yes, the real use is for example, retrieving form variables like usernames, customer name that was set somewhere /some page in the request. – salah-1 Apr 29 '18 at 14:54