thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Login don't work but there no error on page #37

Open adarwash opened 10 years ago

adarwash commented 10 years ago

When i login the the page just refreshes and there is no errors displayed, even if i use error_reporting(-1);

Here my code:

<?php

error_reporting(-1);

# Start session
session_start();

   include ('../config/connection.php');

   if($_POST){

      $q = "SELECT * FROM users WHERE  email = '$_POST[email]' AND password = SHA1('$_POST[password]')";
      $r = mysqli_query($dbc, $q);

      $show = mysqli_fetch_row($r);

      if(mysqli_num_rows($r) == 1){

          $_SESSION['username'] = $_POST['email'];
          echo "You have logged in sucessfully";
          } else {
              echo "Somthing has gone worng <br>";
               echo "Google say ".$show['email'];
               echo $_POST; 
              }
       }

   include ('config/css.php');
   include ('config/js.php');
   ?>
<!doctype html>
<html>
   <head>
      <title>Admin Login</title>
      <meta name="viewport" content="width=device-width, initial-scale=1">
   </head>
   <body>
      <?php //include(D_TEMPLATE.'/navigation.php');?>
      <div class="container">
        <div class="row">
         <div class="col-md-4 col-md-offset-4">
            <div class="panel panel-info">
               <div class="panel-heading">
                  <strong>Login</strong>
               </div>
               <!-- END Heading -->
               <div class="panel panel-body">

                  <form action="login.php" method="post" role="form">
                     <div class="form-group">
                        <label for="email">Email address</label>
                        <input type="email" class="form-control" id="email"  name="email" placeholder="Email">
                     </div>
                     <div class="form-group">
                        <label for="password">Password</label>
                        <input type="password" class="form-control" id="password" name="password" placeholder="Password">
                     </div>
                     <!--
                        <div class="checkbox">
                          <label>
                            <input type="checkbox"> Check me out
                          </label>
                        </div>
                        -->
                     <button type="submit" class="btn btn-default">Submit</button>
                  </form>
               </div>
               <!-- END panel -->
            </div>
            <!-- END col -->
         </div>
         <!-- END row-->
         </div>
         <h1><?php //echo $page['header']; ?></h1>
         <?php //echo $page['body_formatted']; ?>
      </div>
      <!-- -->
      <?php //include(D_TEMPLATE.'/footer.php');?>  
      <?php //if($debug == 1) {?>
      <?php //require_once('widgets/debug.php'); ?>
      <?php //}?>
   </body>
</html>
thedigicraft commented 10 years ago

Hello,

That is most likely because you are not telling the page to go anywhere once the log in is accepted. You are missing the header() function. Take a look at this file in the repository and check out where that belongs.

thedigicraft commented 10 years ago

I looked at that file for you... this is how it should look (I know you have added some extra stuff and that is fine..) just make sure that you have that header(); in the right spot


if($_POST) {

    $q = "SELECT * FROM users WHERE email = '$_POST[email]' AND password = SHA1('$_POST[password]')";
    $r = mysqli_query($dbc, $q);

    if(mysqli_num_rows($r) == 1) {

        $_SESSION['username'] = $_POST['email'];
        header('Location: index.php');

    }

}
adarwash commented 10 years ago

Hi,

Thanks for quick response, i have added it and i am still getting the same issue, i made a new user in the data base and still do not work

<?php

error_reporting(-1);

# Start session
session_start();

   include ('../config/connection.php');

   if($_POST){

      $q = "SELECT * FROM users WHERE  email = '$_POST[email]' AND password = SHA1('$_POST[password]')";
      $r = mysqli_query($dbc, $q);

      if(mysqli_num_rows($r) == 1){

          $_SESSION['username'] = $_POST['email'];
          header('location: index.php');
          }
       } 

   include ('config/css.php');
   include ('config/js.php');
   ?>
<!doctype html>
<html>
   <head>
      <title>Admin Login</title>

      <meta name="viewport" content="width=device-width, initial-scale=1">
   </head>
   <body>
      <?php //include(D_TEMPLATE.'/navigation.php');?>
      <div class="container">
        <div class="row">
         <div class="col-md-4 col-md-offset-4">
            <div class="panel panel-info">
               <div class="panel-heading">
                  <strong>Login</strong>
               </div>
               <!-- END Heading -->
               <div class="panel panel-body">

                  <form action="" method="post" role="form">
                     <div class="form-group">
                        <label for="email">Email address</label>
                        <input type="text" class="form-control" id="email"  name="email" placeholder="Email">
                     </div>
                     <div class="form-group">
                        <label for="password">Password</label>
                        <input type="password" class="form-control" id="password" name="password" placeholder="Password">
                     </div>
                     <!--
                        <div class="checkbox">
                          <label>
                            <input type="checkbox"> Check me out
                          </label>
                        </div>
                        -->
                     <button type="submit" class="btn btn-default">Submit</button>
                  </form>
               </div>
               <!-- END panel -->
            </div>
            <!-- END col -->
         </div>
         <!-- END row-->
         </div>
         <h1><?php //echo $page['header']; ?></h1>
         <?php //echo $page['body_formatted']; ?>
      </div>
      <!-- -->
      <?php //include(D_TEMPLATE.'/footer.php');?>  
      <?php //if($debug == 1) {?>
      <?php //require_once('widgets/debug.php'); ?>
      <?php //}?>
   </body>
</html>
thedigicraft commented 10 years ago

The problem may be at the point that you ask the database to check the email/password. This following IF statement does not seem to be returning true, otherwise it would be running the header() function.


      if(mysqli_num_rows($r) == 1){

          $_SESSION['username'] = $_POST['email'];
          header('location: index.php');
          }

Maybe add some error handling/debugging here:


      if(mysqli_num_rows($r) == 1){

          $_SESSION['username'] = $_POST['email'];
          header('location: index.php');
      } else {

          echo mysqli_error($dbc).'<br>'.$q; // show any mysql errors and echo out the query to look for other errors     

      }
adarwash commented 10 years ago

I have added the debugging and this is result i get

 SELECT * FROM users WHERE email = 'root@root.com' AND password = SHA1('Password')