PHP / HTML:在PHP会话变量中保存HTML变量

时间:2022-09-20 11:13:41

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.

我知道这对你们大多数人来说都是非常基本的,但我只是找不到我需要的信息。我今天开始使用HTML / PHP / JavaScript(没有任何经验)。我的情况是我有一个带输入字段的html表单,这个输入字段应保存到php-session-variable。我实现的是在按下提交按钮后获取以下.php站点中的变量,然后将其存储在会话变量中。

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?

那是超级难看的,不是吗?它就像在栅栏上扔石头,只是为了在下一刻跑来跑去,再把它们捡起来。如何直接将信息保存到提交的会话字段中?

1 个解决方案

#1


2  

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.

希望能帮助到你。

#1


2  

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.

希望能帮助到你。