dongshungai4857
dongshungai4857
2015-05-31 23:31

将会话更改为电子邮件会话

已采纳

this session is about the username, and i want to make a session for an email, i tryd soo much but everything i try, doesnt work. Can someone help me to make a new session for email

<?php

session_start();
header('Content-type: text/html;charset=UTF-8');
if(!isset ($_SESSION['username']) and isset($_COOKIE['username'], $_COOKIE['password']))
{
    $cnn = mysql_query('select password,id from users where username="'.mysql_real_escape_string($_COOKIE['username']).'"');
    $dn_cnn = mysql_fetch_array($cnn);
    if(sha1($dn_cnn['password'])==$_COOKIE['password'] and mysql_num_rows($cnn)>0)
    {
        $_SESSION['username'] = $_COOKIE['username'];
        $_SESSION['userid'] = $dn_cnn['id'];
    }
}
?>
<?php

echo htmlentities($_SESSION['username']); 

?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dongxia2068 dongxia2068 6年前

    Thanks everyone for helping!

    I did just a few second ago and it works perfectly!

    点赞 评论 复制链接分享
  • douqiang6036 douqiang6036 6年前

    You can do this way,

    session_start();
    header('Content-type: text/html;charset=UTF-8');
    if(!isset ($_SESSION['username']) and isset($_COOKIE['username'],$_COOKIE['password']))
    {
       $cnn = mysql_query('SELECT password,id,email from users where username="'.mysql_real_escape_string($_COOKIE['username']).'"');
       $dn_cnn = mysql_fetch_array($cnn);
       if(sha1($dn_cnn['password'])==$_COOKIE['password'] and mysql_num_rows($cnn)>0)
       {
        //$_SESSION['username'] = $_COOKIE['username'];
        $_SESSION['userid'] = $dn_cnn['id'];
        $_SESSION['email'] =  $dn_cnn['email'];
        }
    }
    

    This should set the session as an email. But remember you have to select email field from the users table if there is any email field that exists.

    点赞 评论 复制链接分享
  • dongzong5017 dongzong5017 6年前

    **

    yes!

    session_start();
    header('Content-type: text/html;charset=UTF-8');
    if(!isset($_SESSION['username']) and isset($_COOKIE['username'], $_COOKIE     ['email']))
     {
      $cnn = mysql_query('select email, from users where              username="'.mysql_real_escape_string($_COOKIE['username']).'"');  $dn_cnn = mysql_fetch_array($cnn);
    if(sha1($dn_cnn['email'])==$_COOKIE['email'] and mysql_num_rows($cnn)>0)
    {
        $_SESSION['username'] = $_COOKIE['username'];
        $_SESSION['userid'] = $dn_cnn['email'];
    }
     }
     ?>
     <?php
    
     echo htmlentities($_SESSION['userid']); 
    
    ?>
    

    now i get as id 1 :( i dont want that id :P **

    点赞 评论 复制链接分享

为你推荐