简单的会话示例不起作用 [英] Simple session example not working
本文介绍了简单的会话示例不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了这个小会话脚本,我看到它不起作用。
I writed this little session script and i saw that's not working.
<?php
session_start();
$username = $_SESSION["username"];
?>
<html><head>
<title>Simple Session Example</title>
</head>
<body>
<?
if(isset($_SESSION['username'])) {
$username = $_POST["username"];
echo "<h3>Hello $username</h3>";
}
else {
echo "<h3>OUT!</h3>";
echo "<form action='index.php' method='POST'>";
echo "<input type='text' name='username'>";
echo "<input type='submit' name='submit' value='Submit'></form>";
}
?>
我无法弄清楚哪一部分是错误的。看起来对m来说都很好但是肯定是错的。
I can't figure out which part is wrong. looks all good for m but definatelly something is wrong.
推荐答案
这样的东西?
<?php
session_start();
if(isset($_SESSION['username']))
$username = $_SESSION["username"];
?>
<html><head>
<title>Simple Session Example</title>
</head>
<body>
<?
if(isset($_POST['username'])) {
$username = $_POST["username"];
$_SESSION["username"] = $_POST["username"];
echo "<h3>Hello $username</h3>";
}
else if($username) {
echo "<h3>Hello $username</h3>";
}
else {
echo "<h3>OUT!</h3>";
echo "<form action='index.php' method='POST'>";
echo "<input type='text' name='username'>";
echo "<input type='submit' name='submit' value='Submit'></form>";
}
?>
这篇关于简单的会话示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文