Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP/HTML: Saving HTML variables in PHP Session variables

I know this will be very basic for the majority of you, but I just dont find the information I need. I started today with HTML/PHP/JavaScript (no experience in any of those 3). My situation is that I have a html form with a input-field and this input field shall be saved to a php-session-variable. What I achieved is after pushing the submit button getting the variable in the following .php site and then store it in the session variable.

That is super ugly, isnt it? Its like throwing stones over a fence just to run around in the next moment and picking them up again. How can I directly save information into the session fields on a submit?

like image 975
toobee Avatar asked Aug 25 '26 02:08

toobee


1 Answers

That IS the right way! You should throw information at server and let it save it into sessions!

Sessions are not accessible from client side, that's the fence you mentioned!

To be more accurate:

Throwing over the fence:

<form method="post" name="contact" action="">
    <label for="author">author:</label>
    <input type="text" id="author" name="author"/>
    <input type="submit" value="submit" id="submit" name="submit"/>
</form>

Running around and checking for stone:

if(isset($_POST['submit'])) //Stone found

Picking them up and putting them in their place(!):

session_start();
$_SESSION['their_place']=$_POST['author'];

Hope It Helps.

like image 97
aliqandil Avatar answered Aug 27 '26 16:08

aliqandil