求php中传递登录信息代码

就是把用户的登录信息传递给下个页面,而且一直保存,其他内部页面也可以直接获得
就是需要详细代码,简单一点就可以
2楼的只能提交给一个页面,不能在其他页面访问啊

session,或cookie
表单提交的页面
<?php
session_start();
$username = trim($_POST['username']);
$password = md(trim($_POST['password']));
if(这里对比数据库用户名密码是否正确){
setcookie('username',$username);
}else{
提示用户名或密码不正确
}
?>

另一个页面
<?php
session_start();
echo $_SESSION['username'];
?>

有什么问题M我
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-07-20
登陆页面login.php
<?
$database_localhost="localhost";
$database_username="root"; //使用数据库的用户名
$database_password=""; //数据库的密码
$database_name=""; //数据库名称
session_start();

if($login_submit){
$db_id=mysql_connect($database_localhost,$database_username,$database_password);
$result=mysql_db_query($database_name,"select * from usertab where user='$c_user' limit 1");
$row=mysql_fetch_array($result);
$num=mysql_num_rows($result);
mysql_close($db_id);
if($num==0) $str="您的用户名不存在!";
else if($row[password]!=$c_pwd) $str="您的密码不正确!";
else{
session_register("ses_user");//写入session
$ses_user=$row[user];
header("location:index.php");
}
}

?>
<html>
<head><title>用户登录</title>
</head>
<style>
table{font-size:9pt;}
</style>
<body><br>
<form name="form1" method="post" action= >
<table border="0" cellpadding="3" cellspacing="1" align="center" width="300" bgcolor="#3399CC">
<tr height="25" bgcolor="#E7E7E7"><td colspan="2"><b></b>用户登录</td></tr>
<tr height="25" bgcolor="#e7f7f7" ><td align="right">用户名:</td><td><input type="text" name="c_user"></td></tr>
<tr height="25" bgcolor="#e7f7f7" ><td align="right">密码:</td><td><input type="password" name="c_pwd"></td></tr>
<tr height="25" bgcolor="#e7f7f7" ><td></td><td><input type="submit" name="login_submit" value="用户登录"><?echo "<font color=red>".$str."</font>";?></td></tr>
</table>
</form>

登陆后跳转页面index.php
<?
session_start();
if($ses_user==""){
echo "未登陆,跳转到登陆页面...";
sleep(5);
header("login.php");
}
?>
第2个回答  2010-07-20
看示例:

-----a.htm---------:
<form action=b.php method=post>
<input type=text name=aaa>
<input type=submit value=提交>
</form>

-----b.php---------:
<?php
$aaa=$_POST["aaa"];
echo "$aaa";
?>
第3个回答  2010-07-20
session 或cookie 保存下来就OK 详情自己寻找

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网