重定向到欢迎页面时,会话变为空白 [英] Session is getting blank when redirecting to welcome page
问题描述
你好
再次是我,我有这个注册页面,当用户登录时应该将你重定向到欢迎页面,我遇到了类似的问题对于遇到同样问题的一个用户来说。
一次进入欢迎页面,但是firstname和lasname变量中有错误。如何回应它。显然我有错误的代码,所以它正在接收错误,尝试修复,我不知道我做了或不知道现在当我尝试注册时,它是空白的
i也有一个登录页面,而且一切都不起作用。这是2套代码。一个是register.php,另一个是欢迎页面代码。
这是我到目前为止所拥有的。我知道我在提出这个问题之前已经问了这个问题
我尝试过的事情:
< pre > <? php
session_start();
if(isset($ _ SESSION [' user']))
{
header(' Location:login.php');
}
?>
<? xml version = 1.0 encoding = UTF-8 ?>
< !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.1 // EN
http://www.w3.org/TR/xhtml11.dtd & gt;
< html xmlns = http:www.w3.org/1999/xhtml xml:lang = < span class =code-keyword> zh lang = zh >
< head >
< title > 欢迎 - <? php echo 。$ _ SESSION [' user']; ?> < / title < span class =code-keyword>>
< / head >
< body >
欢迎!!! <? php echo $ _POST [' firstname']; ?> < !< br / > <? php echo $ _POST [' lastname']; ?>
<? php
echo 您现在是加勒比海烹饪网络(CCIN)的成员。
您的每月时事通讯将通过电子邮件发送给您。
?>
< / body >
< / html >
这是register.php代码
< pre > <? php
if(isset($ _ POST [' submit']))
{
// 捕获变量从形式和存储在PHP变量
$ title = $ _ POST [' 标题跨度>];
$ firstname = $ _ POST [' firstname'];
$ lastname = $ _ POST [' lastname'];
$ address = $ _ POST [' address'];
$ txtemail = $ _ POST [' txtemail'];
$ gender = $ _ POST [' gender'];
$ userName = $ _ POST [' userName'];
$ pword = $ _ POST [' pword'];
// 连接服务器
$ db_host = localhost;
$ db_username = root;
$ db_password = ;
$ con = mysqli_connect($ db_host,$ db_username,$ db_password)或 die(mysqli_connect_error) ());
// 选择要查询的数据库
mysqli_select_db($ con,' food')或 die(mysqli_error($ con));
$ sql = SELECT * FROM member WHERE userName ='$ userName';
$ result = mysqli_query($ con,$ sql)或 die( 错误: .mysqli_error($ con));
$ rowcount = mysqli_num_rows($ result);
if($ rowcount> = 1)
{
echo < script type = \text / javascript \;
alert('用户名已存在');
窗口。 location = \register.html \;
< / script>;
} // .....
else
{
// 将数据插入表格
$ sql = INSERT INTO成员VALUES('$ title','$ firstname','$ lastname',
'$ address','$ txtemail','$ gender','$ userName',MD5('$ PWORD'))跨度>;
if(mysqli_query($ con,$ sql))
{
mysqli_close($ con);
header( location:welcome.php);
}
其他
{
echo 插入数据库时出错 .mysqli_error($ con);
}
} // .. .....
}
?>
_SESSION [' user' ]))
{
header(' 位置:login.php'< /跨度>);
}
?>
<? xml version = 1.0 encoding = UTF-8 ?>
< !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.1 // EN
http://www.w3.org/TR/xhtml11.dtd & gt;
< html xmlns = http:www.w3.org/1999/xhtml xml:lang = < span class =code-keyword> zh lang = zh >
< head >
< title > 欢迎 - <? php echo 。
_SESSION [' user'< /跨度>]; ?> < / title < span class =code-keyword>>
< / head >
< body >
欢迎!!! <? php echo
_POST [' firstname']; ?> < !< br / > <? php echo
hi there
it is me again, i have this registration page when a user login it should redirect you to a welcome page, I am having a similar problem at to one user who was experiencing the same problem.
at one time it was going to the welcome page, but there were errors in the firstname an lasname variable. how to echo it out. apparently i had code it wrong, so it was picking up the error, try fixing and I have no idea I did or didn't know now when i tried registering, it is blank
i have a login page also and that and all is not working. here is the 2 sets of codes. one is the register.php and the other is the welcome page codes.
this is what i have so far. i know that I have asked this question before abot the name
What I have tried:
<pre><?php
session_start();
if(isset($_SESSION['user']))
{
header('Location:login.php');
}
?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11.dtd">
<html xmlns="http:www.w3.org/1999/xhtml"xml:lang="en" lang="en">
<head>
<title> Welcome - <?php echo "".$_SESSION['user']; ?></title>
</head>
<body>
Welcome!!! <?php echo $_POST['firstname']; ?><!<br/><?php echo $_POST['lastname'];?>
<?php
echo " you are now a member of the Caribbean Culinary Network (CCIN).
Your monthly newsletter will be email to you."
?>
</body>
</html>
this is the register.php code
<pre><?php
if(isset($_POST['submit']))
{
//capture the variable from the form and store in php variables
$title=$_POST['title'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$address=$_POST['address'];
$txtemail=$_POST['txtemail'];
$gender=$_POST['gender'];
$userName=$_POST['userName'];
$pword=$_POST['pword'];
//connecting to the server
$db_host="localhost";
$db_username="root";
$db_password="";
$con = mysqli_connect($db_host,$db_username,$db_password) or die (mysqli_connect_error());
//select the database you want to query
mysqli_select_db($con, 'food') or die (mysqli_error($con));
$sql = "SELECT * FROM member WHERE userName = '$userName'";
$result = mysqli_query($con, $sql) or die ("Error:".mysqli_error($con));
$rowcount=mysqli_num_rows($result);
if($rowcount >= 1)
{
echo "<script type=\"text/javascript\";
alert('username already exist');
window.location=\"register.html\";
</script>";
}//.....
else
{
//insert data into table
$sql = "INSERT INTO member VALUES('$title', '$firstname', '$lastname',
'$address', '$txtemail', '$gender', '$userName', MD5('$pword'))";
if(mysqli_query($con, $sql))
{
mysqli_close($con);
header("location:welcome.php");
}
else
{
echo "Error inserting into database".mysqli_error($con);
}
}//.......
}
?>
_SESSION['user'])) { header('Location:login.php'); } ?> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11.dtd"> <html xmlns="http:www.w3.org/1999/xhtml"xml:lang="en" lang="en"> <head> <title> Welcome - <?php echo "".
_SESSION['user']; ?></title> </head> <body> Welcome!!! <?php echo
_POST['firstname']; ?><!<br/><?php echo
这篇关于重定向到欢迎页面时,会话变为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!