Jump to content

Recommended Posts

Hello,

 

I'm trying to build a registration/login system.

 

I managed to set it up but i need that for the user when he/she is logged in to display his own information and to manage to edit them, First i need to display them, because i seem to not be doing it.. i know it's easy in principal but i am really new at this...

 

So here is my code:

 

The login.php page

 

<?php



include ('database_connection.php');
if (isset($_POST['formsubmitted'])) {
    // Initialize a session:
session_start();
    $error = array();//this aaray will store all error messages
  

    if (empty($_POST['e-mail'])) {//if the email supplied is empty 
        $error[] = 'You forgot to enter  your Email ';
    } else {


        if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) {
           
            $Email = $_POST['e-mail'];
        } else {
             $error[] = 'Your EMail Address is invalid  ';
        }


    }


    if (empty($_POST['Password'])) {
        $error[] = 'Please Enter Your Password ';
    } else {
        $Password = $_POST['Password'];
    }


       if (empty($error))//if the array is empty , it means no error found
    { 

       

        $query_check_credentials = "SELECT * FROM members WHERE (Email='$Email' AND password='$Password') AND Activation IS NULL";
   
        

        $result_check_credentials = mysqli_query($dbc, $query_check_credentials);
        if(!$result_check_credentials){//If the QUery Failed 
            echo 'Query Failed ';
        }

        if (@mysqli_num_rows($result_check_credentials) == 1)//if Query is successfull 
        { // A match was made.

           


            $_SESSION = mysqli_fetch_array($result_check_credentials, MYSQLI_ASSOC);//Assign the result of this query to SESSION Global Variable
           
            header("Location: page.php");
          

        }else
        { 
            
            $msg_error= 'Either Your Account is inactive or Email address /Password is Incorrect';
        }

    }  else {
        
        

echo '<div class="errormsgbox"> <ol>';
        foreach ($error as $key => $values) {
            
            echo '   <li>'.$values.'</li>';


       
        }
        echo '</ol></div>';

    }
    
    
    if(isset($msg_error)){
        
        echo '<div class="warning">'.$msg_error.' </div>';
    }
    /// var_dump($error);
    mysqli_close($dbc);

} // End of the main Submit conditional.



?><!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>Login Form</title>


   
   
   
<style type="text/css">
body {
   font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
   font-size:12px;
}
.registration_form {
   margin:0 auto;
   width:500px;
   padding:14px;
}
label {
   width: 10em;
   float: left;
   margin-right: 0.5em;
   display: block
}
.submit {
   float:right;
}
fieldset {
   background:#EBF4FB none repeat scroll 0 0;
   border:2px solid #B7DDF2;
   width: 500px;
}
legend {
   color: #fff;
   background: #80D3E2;
   border: 1px solid #781351;
   padding: 2px 6px
}
.elements {
   padding:10px;
}
p {
   border-bottom:1px solid #B7DDF2;
   color:#666666;
   font-size:11px;
   margin-bottom:20px;
   padding-bottom:10px;
}
a{
    color:#0099FF;
font-weight:bold;
}

/* Box Style */


.success, .warning, .errormsgbox, .validation {
   border: 1px solid;
   margin: 0 auto;
   padding:10px 5px 10px 60px;
   background-repeat: no-repeat;
   background-position: 10px center;
     font-weight:bold;
     width:450px;
     
}

.success {
   
   color: #4F8A10;
   background-color: #DFF2BF;
   background-image:url('images/success.png');
}
.warning {

   color: #9F6000;
   background-color: #FEEFB3;
   background-image: url('images/warning.png');
}
.errormsgbox {

   color: #D8000C;
   background-color: #FFBABA;
   background-image: url('images/error.png');
   
}
.validation {

   color: #D63301;
   background-color: #FFCCBA;
   background-image: url('images/error.png');
}



</style>

</head>
<body>


<form action="login.php" method="post" class="registration_form">
  <fieldset>
    <legend>Login Form  </legend>

    <p>Enter Your username and Password Below  </p>
   
    <div class="elements">
      <label for="name">Email :</label>
      <input type="text" id="e-mail" name="e-mail" size="25" />
    </div>

    <div class="elements">
      <label for="Password">Password:</label>
      <input type="password" id="Password" name="Password" size="25" />
    </div>
    <div class="submit">
     <input type="hidden" name="formsubmitted" value="TRUE" />
      <input type="submit" value="Login" />
    </div>
  </fieldset>
</form>
Go Back to <a href="#">Account Verification on sign up</a>
</body>
</html>

 

This is the page's code where user is redirected after login

 

<?php
   ob_start();
    session_start();
    if(!isset($_SESSION['Username'])){
         header("Location: login.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>Member Area </title>
<style type="text/css">
.success {
   border: 1px solid;
   margin: 0 auto;
   padding:10px 5px 10px 60px;
   background-repeat: no-repeat;
   background-position: 10px center;
     font-weight:bold;
     width:450px;
     color: #4F8A10;
   background-color: #DFF2BF;
   background-image:url('images/success.png');
     
}



</style>
</head>

<body>
<div class="success">Welcome , <?php echo $_SESSION['Username']   ; ?></div>
<?
$b = time ();
$date1 =date( "Y-m-d;h:i:s" , mktime(date("h")+6, date("i"), date("s"), date("m") , date("d"), date("Y")));
$str_time = "&receivedtimestamp=";
$str_msg = "&msg=bkt";
$str_from = "from=";


?>
<a href="http://testext.i-movo.com/api/receivesms.aspx?<?echo $str_from;?><?echo $_SESSION['phone'];?><?echo $str_time;?><?echo $date1;?><?echo $str_msg;?>">Get a Cupon</a>

</br>
<?php echo $_SESSION['Email']   ; ?>
</br>
<?php echo $_SESSION['phone']   ; ?>


  <p><strong>My Account</strong></p>
  <a href="myaccount.php">My Account</a><br>
  <a href="mysettings.php">Settings</a><br>
    <a href="logout.php">Logout </a>


</body>
</html>

 

And finally the database structure is this one ...

 

CREATE TABLE IF NOT EXISTS `members` (
  `Memberid` int(10) NOT NULL AUTO_INCREMENT,
  `Username` varchar(20) NOT NULL,
  `Email` varchar(50) NOT NULL,
  `Password` varchar(10) NOT NULL,
  `phone` varchar(25) NOT NULL,
  `Activation` varchar(60) DEFAULT NULL,
  PRIMARY KEY (`Memberid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=30 ;

 

Please help me with this because i'm going mad :(

 

First i need to display them, because i seem to not be doing it..

 

Since you didn't state or show what incorrect result you got, it's not possible for anyone here, who is not standing right next to you, to help. What exact error or exact symptom did you see in front of you that leads you to believe that you seem to not be doing it? I can name at least 6 different symptoms you might have gotten, ranging from the wrong page (no redirect) to a broken/partial page being output. You need to narrow down the problem by communicating what exactly occurred and at what point in the process it occurred at. And if you did get a blank or partial page, what does the 'view source' of that page in your browser show?

 

You also need an exit; statement after your header() redirect to prevent the remainder of the code on your page from running while the browser requests the new page. Your existing if(!isset($_SESSION['Username'])){header("Location: login.php");} logic won't stop a hacker or bot script from accessing that page (all they have to do is ignore the header redirect.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.