Current location: Hot Scripts Forums » Programming Languages » PHP » Redirect after login trouble

Redirect after login trouble

 
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-01-09, 02:08 PM
WillUK WillUK is offline
Newbie Coder
 
Join Date: Jan 2009
Location: Beverley, England
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Redirect after login trouble

Hi Guys

I am probably doing something really silly here, but I can't see what exactly it is...
Basically, I want to redirect the user to 'index.php' after the user has logged in to the application....

I know that the connection to SQL is ok, because users can register without any trouble....So it can't be that.

All I can think is that I am perhaps calling the session variable, $_SESSION['customer_id']; , from the wrong place in the script.

What is currently happening is that the login form renders correctly on my VDU, but once the user has entered their details into the form, and clicked 'submit', a white screen appears (i.e. a blank page).

I have used this script a number of times before, and have not experienced this problem until now, so that makes it doubly frustrating....

The SQL format for the table 'customer' is:

customer_id (INT), email (VARCHAR), password (VARCHAR), card_number (BLOB)


PHP Code:
  # Script 7.7 - login.php

if (isset($_POST['submit'])) {
    require_once (
'../mysql_connect.php');
    function 
escape_data ($data) {
        global 
$dbc;
        if (
ini_get('magic_quotes_gpc')) {
            
$data stripslashes($data);
        }
        return 
mysql_real_escape_string($data$dbc);
    }
    
$message NULL;
    if (empty(
$_POST['email'])) {
        
$e FALSE;
        
$message .= '<p>Please enter an email address</p>';
    } else {
        
$e escape_data($_POST['email']);
    }
    if (empty(
$_POST['password'])) {
        
$p FALSE;
        
$message .= '<p>Please enter your password</p>';
    } else {
        
$p escape_data($_POST['password']);
    }
    
    if (
$e && $p) { // If everything's OK.
        
$query "SELECT customer_id FROM customer WHERE email= '$e' AND password= '$p' ";        
        
$result = @mysql_query ($query);
        
$row mysql_fetch_array ($resultMYSQL_NUM); 
        if (
$row) { 
                
                
// Start the session, register the values & redirect.
                
session_start();
                
$_SESSION['customer_id'] = $row;
                
header ("Location:  http://" $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "./index.php");
                exit();
                
        } else {
            
$message '<p>The email and password entered do not match those on file.</p>'
        }
        
mysql_close();
    } else {
        
$message .= '<p>Please try again.</p>';        
    }
}
$page_title 'Login';
include (
"includes/main_body.php");
if (isset(
$message)) {
    echo 
'<font color="red">'$message'</font>';

HTML Code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>Email:</b> <input type="text" name="email" size="25" maxlength="20" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p><b>Password:</b> <input type="password" name="password" size="20" maxlength="20" />
</p>
<div align="center"><input type="submit" name="submit" value="Login" /></div>
</fieldset>
</form><!-- End of Form -->
PHP Code:
include ("includes/footer.php"); 

Any pointers would be appreciated.

cheers.
Will
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
 

Bookmarks

Tags
login, php, redirect, sessions


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect code in this login form code. Dreadlox PHP 2 12-15-08 06:27 AM
Help with multiple user login and redirect Spotted_Doe New Members & Introductions 3 01-30-06 01:12 AM
Login Redirect Jig0901 ASP.NET 2 04-17-05 05:40 AM
Login and Redirect user script alistairgd Script Requests 4 01-03-05 04:30 PM
Redirect previous 2 pages after login mcrob PHP 5 01-01-05 08:35 AM


All times are GMT -5. The time now is 06:21 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.