Jump to content
Larry Ullman's Book Forums

Problem With Login


Recommended Posts

Hi,

 

Having a bit of a problem with regard to someone logging in on my site. It will not display Register page if I include certain files.

 

Here is my header.php file which stores all the navigation links, and the sign-in option or to display their profile options:

 

<body>
<section class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand text-info" href="http://www.webzoost.com" name="top">abaloo</a>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
 <li><a href="http://www.webzoost.com/profiles/register.php">register</a></li>
 <li class="divider-vertical"></li>
 <li><a href="#">search</a></li>
 <li class="divider-vertical"></li>
 <li class="dropdown">
<?php
if (isset($_SESSION['user_id'])) {
 echo '<a class="dropdown-toggle" href="#" data-toggle="dropdown">Your Profile <strong class="caret"></strong></a>
 <div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">';
} else {
 echo '<a class="dropdown-toggle" href="#" data-toggle="dropdown">sign in <strong class="caret"></strong></a>
 <div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">';
	 require ('includes/login_form.inc.php');
}
?>


 </div>
 </li>
</ul>
</div>
</div>
</div>
</section>

 

Now the problem comes when i add the following files:

 

- login.inc.php

 

since when i put this file in my index.php file I cannot seem to link to any other part of the website such as "register" which then throws up a blank page, but if I take out the file all-together then register displays.

 

So what I am saying is where do I put file (login.inc.php) with-out it interfering with other links on my website, also could it be a directory issue, I know larry has his navigation in the footer, but mine is in the header.php file.

 

here is my directory setup:

 

index

profiles

- register.php

includes

- login.inc.php

- login_form.inc.php

- header.php // This is where all my navigation is, and also the login form as well.

- footer.php

 

I am now getting the following error when I only view the source code, this error is not being displayed for some reason on output to the user(I can't find an option to paste a screenshot/image of the code):

 

An error occurred in script '/home/sites/webzoost.com/public_html/includes/header.php' on line 52:<br />
require(includes/login_form.inc.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory<br />
<pre>Array<br />

 

 

Any comments, suggestions would be much appreciated.

 

 

PHP5

MySQL5

Chrome

Link to comment
Share on other sites

I don't really understand if you have your login in your Index file or header file but don't see a reason why a person couldn't login on either of those two pages.

 

One thing I think you have to do is set up the required php documents like the following – require ('./includes/login_form.inc.php')

 

Marie

Link to comment
Share on other sites

I have changed the directory structure, to the one that is the same as in the E-Commerce book, the only difference is that my Login form is in the header rather than the footer.

 

Now for some reason whenever a user tries to go to any other page, all they get is a blank page with just the header displaying.

 

I did have require ('./includes/login_form.inc.php');

 

But that did not originally work so I changed it to include instead.

 

How would the scripts change from example 1 in the E-Commerce book:

 

My navigation is in the Header.html file rather than the Footer.html file, That is the only difference from the example in the book ?

 

And all I am seeing on other pages is white space and the header file.

 

Any comments, suggestions would be much appreciated.

Link to comment
Share on other sites

Okay I understand that your navigation and login form is in your header file rather than your footer file and that you are following the book for the most part. The fact that you have your navigation and login in your header file or footer file shouldn't make any difference. That should work. For instance mine is neither in the header or footer.

 

In your above post you show only four files in your includes file. I do not see a form_functions.inc.php or config.inc.php in your list. I believe that your login.inc.php should stay in that directory. Also, if you have changed the title of that folder then make sure that it is spelled that way in all of your references.

 

Check and make sure where you posting is going to once your user hits "submit". In the book, I believe that once a person has logged on they go to the Index.php page. Maybe that isn't where you want your logged in user to end up - in your site.

 

Marie

Link to comment
Share on other sites

My Directory structure is set up exactly the same way as in the book:

 

Index

Includes

- LoginForm.php (displays the form)

- Login.inc.php (processes the form)

- config.inc.php (setup for the website directory structure)

- Header.php (display all relevant head information(titles, meta,)

- Footer.php (holds all the Javascript files, also ends with the html,body)

 

 

==================================================================

Top of my Index.php file

 

<?php
require ('./includes/config.inc.php');

require (MYSQL);
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
 include ('./includes/login.inc.php');
}
include ('./includes/header.php');
?>

 

Now here is header.php file:

 

<?php
if (isset($_SESSION['user_id'])) {
echo '<ul class="nav pull-right">
<li><a href="http://www.webzoost.com/postJob.php">post job</a></li>
<li class="divider-vertical"></li>
<li><a href="http://www.webzoost.com/resumeSearch.php">search</a></li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">Your Profile <strong class="caret"></strong></a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
<ul class="unstyled">
<li><a href="http://www.webzoost.com/change_password.php">Change Password</a></li>
<li class="divider"></li>
<li><a href="http://www.webzoost.com/logout.php">Logout</a></li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</div>
</section>';
} else {
echo '<ul class="nav pull-right">
<li><a href="http://www.webzoost.com/register.php">register</a></li>
<li class="divider-vertical"></li>
<li><a href="http://www.webzoost.com/search.php">search</a></li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">sign in <strong class="caret"></strong></a>
<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">';
require ('includes/loginForm.php');
echo '</div>
</li>
</ul>
</div>
</div>
</div>
</section>';
}
?>

 

Now here is loginForm.php file:

 

<?php
if (!isset($login_errors)) $login_errors = array();
require_once ('./includes/form_functions.inc.php');
?>
<form action="index.php" id="form-search" method="post"  accept-charset="utf-8">
<?php if (array_key_exists('login', $login_errors)) {
  echo '<span class="alert alert-error">' . $login_errors['login'] . '</span><br />';
 } ?>
 Email
 <?php create_form_input('email', 'text', 'input-large', $login_errors); ?>
 <br />
 Password
 <?php create_form_input('password', 'password', 'input-large', $login_errors); ?>
  <input class="btn btn-primary btn-block" type="submit" id="sign-in" value="Sign In">
</form>
<hr>
<a href="http://www.webzoost.com/forgot_password.php" class="small">Forgotten Password</a>
<br /><br />

 

and here is the process part login.inc.php file:

 

<?php
$login_errors = array();
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$e = mysqli_real_escape_string ($dbc, $_POST['email']);
} else {
$login_errors['email'] = 'Enter a valid email address<br />';
}
if (preg_match ('/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){1,32}$/',$_POST['password']) ) {
$p = mysqli_real_escape_string($dbc,$_POST['password']);
} else {
$login_errors['password'] = 'You entered the wrong password<br />';
}
if (empty($login_errors)) { // OK to proceed!
$q = "SELECT id, profile_type, date_joined FROM Profiles WHERE (email='$e' AND password='"  .  get_password_hash($p) .  "')"; 
$r = mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // A match was made.

 $row = mysqli_fetch_array ($r, MYSQLI_NUM);

 $_SESSION['user_id'] = $row[0];
 $_SESSION['username'] = $row[1];

 // Store the data in a session:
 // Only indicate if the user's account is not expired:
 //if ($row[3] == 1) $_SESSION['user_not_expired'] = true;

} else { // No match was made.
 $login_errors['login'] = 'Email address and password do not match those on file.';
}
} // End of $login_errors IF.

 

When a visitor visits the site, they either click on 'register.php' or 'forgot_password.php' but when they do all they get is the 'header.php' file being displayed with the rest of the page white.

 

Any comments, suggestions would be much appreciated.

Link to comment
Share on other sites

I have had this problem and it could mean that the database is not being queried correctly. I am no expert in this but the top of your Index page looks fine and as it is in the book. Your form is posting to your Index page.

 

However, this line does not look correct to me. There is nothing associated with your "date_joined" column.

 

$q = "SELECT id, profile_type, date_joined FROM Profiles WHERE (email='$e' AND password='" . get_password_hash($p) . "')";

The book as this as follows:

 

$q = "SELECT id, username, type, IF(date_expires >= NOW(), true, false) FROM users WHERE (email='$e' AND pass='" . get_password_hash($p) . "')";

 

I would try some different test queries and see what happens.

 

Marie

Link to comment
Share on other sites

@Marie

I have changed the login script to one a one page login script file. That works fine at the moment.

 

@Larry

When you say remove the "includes" from the include line, do you mean this:

 

<?php
include ('loginForm.php');
?>

 

Because I tried that at that moment in time, but then brought up another few errors.

 

Any comments, suggestions would be much appreciated.

Link to comment
Share on other sites

 Share

×
×
  • Create New...