Session_start用户配置文件详细信息 [英] Session_start User Profile Detail

查看:105
本文介绍了Session_start用户配置文件详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习php。我创建了一个注册和登录系统。它工作正常。但我很好奇的是,如何在用户配置文件中显示用户详细信息。例如姓名,姓氏,电子邮件等。我的登录系统是功能,但只显示电子邮件。



$ b

这是我的profile.php代码。 c $ c><?php

session_start();
if(!isset($ _ SESSION ['email'])){

header('location:index2.php');

}
?>

<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional。 dtd>
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< title>无标题文档< / title>
< link href =css / profile.css =stylesheettype =text / css/>


< / head>

< body>
< div id =header>
< div class =header_in>
< div class =logo>< span> EcoWebTr< / span>< / div>
< div class =cik>< a href =cikis.php>Çıkış< / a>< / div>
<! - 登录信息 - >< / div>
< / div>
< div class =container>
< div class =wrapper>
用户电子邮件:
< font color =#000066><?php echo $ _SESSION ['email']; ?>< / font>

< / div>
< / div>

< / body>
< / html>

这也是login.php

 <?php 
include(includes / connect.php);

if(isset($ _ POST ['login'])){

$ email = $ _POST ['email'];
$ password = md5($ _ POST ['password']);

$ check_user =SELECT * FROM users WHERE email ='$ email'AND password ='$ password';

$ run = mysql_query($ check_user);

if(mysql_num_rows($ run)> 0){
$ _SESSION ['email'] = $ email;


echo< script> window.open('profile.php','_ self')< / script&

} else {

echo< script> alert('wrong email or password')< / script&

}

}
?>


解决方案

您可以采用几种不同的方法。



有一种可能性,因为您说您的登入资讯运作正常,而且我发现您在会话变数中看到电子邮件 登录)还要为要显示的其他字段设置会话变量。



因此,设置名字,姓氏,电子邮件等都是会话变量。然后,在HTML中,您可以根据需要引用这些内容。例如,<?php echo $ _SESSION ['first name']; ?>



UPDATE



您提供的附加信息,以下是一个简短的示例...

  if(mysql_num_rows($ run)> 0){
$ _SESSION ['email'] = $ email;

$ row = mysql_fetch_assoc($ run);
$ _SESSION ['firstname'] = $ row ['firstname'];
$ _SESSION ['lastname'] = $ row ['lastname'];
// etc

此示例假设您在名称数据库为firstname和lastname。只需根据需要调整名称以匹配数据库。这< em>创建所有会话变量...然后您可以根据需要访问它们,就像访问您的电子邮件会话变量一样。


I am learning php. I created a registration and login system. It works fine. But I'm curious about something: how can i display user details in user profile. For example name, surname, email etc. My login system IS functional but displays only email.

This is my profile.php code.

<?php 

  session_start();
if (!isset($_SESSION['email'])) {

    header('location: index2.php');

    } 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="css/profile.css" rel="stylesheet" type="text/css" />


</head>

<body>
<div id="header">
<div class="header_in">
  <div class="logo"><span>EcoWebTr</span></div>
  <div class="cik"><a href="cikis.php">Çıkış</a></div>
  <!--Login informtion--></div>
</div>
<div class="container">
<div class="wrapper">
User Email:
<font color="#000066"><?php echo $_SESSION['email']; ?></font>

</div>
</div>

</body>
</html>

And also this is login.php

<?php
include("includes/connect.php");

if(isset($_POST['login'])) {

  $email = $_POST['email'];
  $password  = md5($_POST['password']);

  $check_user = "SELECT * FROM users WHERE email='$email' AND password='$password'";

  $run = mysql_query($check_user);

  if(mysql_num_rows($run)>0) {
    $_SESSION['email']=$email;


    echo"<script>window.open('profile.php','_self')</script>";

  } else {

    echo"<script>alert('wrong email or password')</script>";

  }

}
?>

解决方案

There are probably several different approaches you can take.

One possibility, since you said your login is working okay, and I see that you are seeing the email in to a session variable (presumably on login) is to also set session variables for other fields you would like to display.

So set first name, last name, email, etc all as session variables. Then, in your HTML, you'll be able to reference those as needed. For example, <?php echo $_SESSION['first name']; ?>

UPDATE

Given the additional info you provided, here's a short example...

if(mysql_num_rows($run)>0) {
  $_SESSION['email']=$email;

  $row = mysql_fetch_assoc($run);
  $_SESSION['firstname'] = $row['firstname'];
  $_SESSION['lastname'] = $row['lastname'];
  // etc

This example assumes that you are storing first name / last name in your database as "firstname" and "lastname". Just adjust the names as needed to match your database. This creates all the session variables... you can then access them as needed just like you accessed your email session variable.

这篇关于Session_start用户配置文件详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆