php中成员的个人资料页面

时间:2015-04-29 13:55:52

标签: php mongodb

这是我的代码php:

的login.php:

<form action="conn.php" method="POST">
    Username:
    <input type="text" id="username" name="username"  />
    Password:
    <input type="password" id="password" name="password" />    
    <input  name="submit" id="submit" type="submit" value="Login" />
</form>
<?php
    $success = "";
    if(isset($_POST['submit']) == "Login" )   
    {
    $username = strip_tags($_POST['username']);
    $password = strip_tags($_POST['password']);
    $error = array();
    // Username Validation
    if(empty($username))
    {
    $error[] = " Empty or invalid username ";
    }
    if(empty($password)){
    $error[] = "Enter your password"; 
    }
    if(count($error) == 0){
     $host = 'localhost';  
    $database_name = 'projett';
    $database_user_name = '';  
    $database_password = '';  
     $connection=new MongoClient();
      if($connection){
    // Select Database
    $database = $connection->$database_name;

    // Select Collection
    $collection = $database->reg_users;
    $user_data= array("username" => $username,"password" => md5($pass));
    $result = $collection->findOne($user_data);
    if($result){
    $success = "You are successully loggedIn";
    header("Location: Articles.php");
    } 
    } else {
    die("Mongo DB not installed");
    } 
    }
    } 
    ?>

registration.php:

<?php 
 session_start();  
 ?>

<!DOCTYPE html>
<html>
    <head>
        <title> Registration </title>
        <meta content="text/html; charset=utf-8" http-equiv="content-type">
        <link href="css/Articles/screen.css" rel="stylesheet">
    </head>
    <body>
        <div id="disposition">
            <div id="header">
                <h1 id="logo">
                    <em align="center"> Registration <em></em>
                </h1>
                <em><span id="slogan"> Registration </span></em>
                <div id="corps">
                    <em></em>
                </div>
            </div>
            <div class="box" id="nav">
                <em></em>
                <ul>
                    <li id="home">
                        <em><a href="Accueil.html">Accueil</a></em>
                    </li>
                    <li>
                        <em><a class="contact" href="contact.html">Contact</a></em>
                    </li>
                </ul>
            </div>
        <div align="center">
        <br>
    </p>

 <form action="registration.php" method="POST">
<b> Pseudo : </b> <br>
<input type="text" id="username" name="username" class="ag" /> <br> <br> 
<b> Email: </b> <br>
<input type="email" id="email" name="email" class="ag" /> <br> <br>
<b> password: </b> <br>
<input type="password" id="password" name="password" class="ag" />  <br> <br> 
<b> Confirm password: </b> <br>
<input type="password" id="c_password" name="confirm_password" class="agrandir" /> <br> <br>
<input  name="submit" id="submit" type="submit" value="Inscription" class="agrandir" /> <br>
</form>
    <br>


  <?php 

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

    //getting post variable 
    $email=strip_tags($_POST['email']);
    $pass=strip_tags($_POST['password']);
    $confirm_pass=strip_tags($_POST['confirm_password']);
    $username=strip_tags($_POST['username']);

    $error = array();

        if(empty($email) or !filter_var($email,FILTER_SANITIZE_EMAIL))
        {
          $error[] = " <h2> complete email  </h2>";
        }
        if(empty($username)){
          $error[] = " <h2> complet username </h2>";
        }
        if(empty($pass)){
          $error[] = " <h2> complet password </h2> ";
        }
        if(empty($confirm_pass)){
          $error[] = " <h2>confirm password !  </h2> ";
        }
        if($pass != $confirm_pass){
           $error[] = " <h2> password not same !  </h2> ";
        }






        if(count($error) ==0){

            //database configuration
             $host = 'localhost';  
             $database_name = 'projett';
             $database_user_name = '';  
             $database_password = '';  

             //if you have database user name & password then connection may be
             //$connection=new Mongo("mongodb://$database_user_name:$database_password@$dbhost");

             //Currently we are connecting to mongodb without authentication
             $connection=new MongoClient();

             //checking the mongo database connection
             if($connection){

                 //connection à la base de donnée
                 $databse=$connection->$database_name;

                 //connection à la collection reg_user
                 $collection=$databse->reg_users;


                  $query=array('username'=>$username);
                 //checking for existing user
                 $count=$collection->findOne($query);

                 if(!count($count)){

                     //Save the New user
                     $user_data=array('email'=>$email,'password'=>md5($pass),'username'=>$username);             
                     $collection->save($user_data);

                     echo " <h2> succes! </h2> ";


                 }else{
                     echo " <h2> username already use </h2> ";
                 }

             }else{

                  die("  <h2> Database are not connected  </h2>"  );
             }

        }else{
            //Displaying the error
            foreach($error as $err){
                echo $err.'<br />';
            }
        }



}

?>
 <footer>

                <p></p>
                <center>
                    <p>
                        © 2015
                    </p>
                </center>
                <br>

        </footer>
 </body>
 </html>

profil.php

 <?php session_start();?>
 Hello, username

    - your email is : 

我想要有关会员的信息:

  • 他填写了登录表格
  • 他转到个人资料页面
  • 在profil.page中
  • 有:

您好,

您的电子邮件是:我不知道获取邮件的代码

1 个答案:

答案 0 :(得分:0)

  1. 我假设您想要用户登录的日期和时间。在我将使用的情况下:
  2. $logdate = date('d/m/Y');

    然后每次将此数据添加到数据库中,以便用户登录以帮助跟踪他们何时登录,或者如果仅在用户访问时使用,则将其添加到会话中。

    1. 当他们进入个人资料页面时,我会像问题1一样做。

    2. 我会创建一个会话并将用户数据存储在该会话中,以便您可以访问个人资料页面上的会话。

    3. 如果您创建了会话,那么您将通过以下方式访问该电子邮件地址:

      $_SESSION['userinfo']['email']; 
      

      创建会话将使访问数据更容易,因为每次需要用户信息时都不必查询数据库。