用户注册成功,直接跳转到首页
如何能让用户一直保持登陆状态?
就像登陆新浪通行证一样求代码,谢谢

解决方案 »

  1.   

    用session 或Cookie来保存信息.
      

  2.   

    <?php session_start();?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>用户注册</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    </head>
    <script language="javascript">
      function chkinput(form){
      
        if(form.admin_user.value==""){
      alert("请输入用户昵称!");
      form.admin_user.select();
      return(false);
    }
       if(form.admin_pass.value==""){
      alert("请输入注册密码!");
      form.admin_pass.select();
      return(false);
    }
       return(true);
      }</script>
    <body>
    <table width="800" height="600" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td align="center" valign="middle"><table width="635" height="372" border="0" align="center" cellpadding="0" cellspacing="0" background="images/dl.gif">
      <form name="form1" method="post" action="index.php"  onsubmit="return chkinput(this)">
        <tr>
          <td width="94" height="299"></td>
          <td width="106"></td>
          <td width="66"></td>
          <td colspan="3"></td>
        </tr>
        <tr>
          <td height="39"></td>
          <td align="center"><input type="text" name="admin_user" class="inputcss" size="14"></td>
          <td></td>
          <td width="106" align="center"><input type="password" name="admin_pass" class="inputcss" size="14"></td>
          <td width="96"><input type="image" name="imageField" src="images/dl_03.gif"></td>
          <td width="167"><input type="image" name="reset" src="images/dl_04.gif" onClick="form.reset();return false;" class="inputcss" ></td>
        </tr>
        <tr>
          <td height="34"></td>
          <td></td>
          <td></td>
          <td colspan="3"></td>
        </tr>
      </form>
    </table></td>
      </tr>
    </table>
    <?php 
     if($_POST['admin_user']!="" || $_POST['admin_pass']!="")
      {
       $conn=new mysqli("localhost","root","123456","db_wlgl");
        $conn->query("set names gb2312");   
        $admin_user=$_POST['admin_user'];
        $admin_pass=md5($_POST['admin_pass']);
        $sql=$conn->query("call admin_regs('".$admin_user."','".$admin_pass."')");
        $res=$sql->fetch_array(MYSQL_BOTH);
        if($res!=NULL){ session_register("admin_user");
    session_register("admin_pass");
       echo "<script>alert('管理员登录成功!');window.location.href='indexs.php';</script>";
    }else{
        echo "<script>alert('管理员登录失败!');</script>";

       
     }
    }
    ?>
    </body>
    </html>
      

  3.   

    同server
    <?php 
    session_name("hello"); //相同名字就可以了
    session_start();
    ?> 不同server, 不同domain :
    不会写就放弃吧, 光这个就可以出一本书了
      

  4.   

    自己继续顶顶设计是这样的:
    首页,无用户ID>点击注册按钮,跳转页面进行注册>注册成功,跳转回首页,带着用户ID
      

  5.   

    seesion 存贮。
    思路:登录成功后 存贮seesion  
    $_SESSION['User']['username']  = $res[0]["username"];
    登录成功后,
    真接读取seesion 的值,
    session_start();
    $username= $_SESSION['User']['username'] 
    $tpl->assign("username",$username);
    然后用smarty 的if else 判断 就可以了