PHP header Function - Not Quite Working.

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
mjjk91
-


Joined: 03 Feb 2004
Posts: 75
Location: Australia

PostPosted: Sun May 30, 2004 7:44 am    Post subject: PHP header Function - Not Quite Working. Reply with quote

G'Day Everyone,

In the following code, i the user fills in their login information from the login.php script, then the page is redirected to the login_form.html script running login.php. It then goes into the "validate" case. Now, in this case, i wish to redirect the user to the page "loggedin.php", to show their login information, and to update my links bar. I have used the "header" function in the line-

header("Location: /loggedin.php");

, but for some reason, it will not re-direct me to this page. I know the rest of my script works, because when i type in the link loggedin.php into my browser, it comes up with all the information i need. So, any ideas why this header function is not working?

Here is my scripts

Cheers

Mick Koch

-------------------------------------------------------------------------------------
login.php

<?php
include $_SERVER['DOCUMENT_ROOT'].
'/layout.php';
switch($_REQUEST['req']){

case "validate":
myheader("Validate!");
$validate = @mysql_query("SELECT * FROM members
WHERE username='{$_POST['username']}'
AND password = md5('{$_POST['password']}')
AND verified='1'");

if(mysql_num_rows($validate) == 1){
while($row = mysql_fetch_assoc($validate)){
$_SESSION['login'] = true;
$_SESSION['userid'] = $row['id'];
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['last_name'] = $row['last_name'];
$_SESSION['email_address'] = $row['email_address'];

if($row['admin_access'] == 1){
$_SESSION['admin_access'] = true;
}

$login_time = mysql_query("UPDATE members
SET last_login=now()
WHERE id='{$row['id']}'");
}
header("Location: /loggedin.php");
} else {
myheader("Login Failed");
echo '<p align="center">Login Failed</p>';
echo '<p align="center">If you have already joined '.
'our website, you may need to validate '.
'your email address. '.
'Please check your email for instructions.';
footer();
}
break;

default:
myheader("Login!");
include $_SERVER['DOCUMENT_ROOT'].
'/html/forms/login_form.html';
footer();
break;
}
?>

-------------------------------------------------------------------------------------
login_form.html

<div align="center"><strong><font size="4" face="Verdana, Arial, Helvetica,
sans-serif">Please
Login </font></strong></div>
<form action="/login.php" method="post">
<table width="30%" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td width="19%"><font size="2" face="Verdana, Arial, Helvetica, sans-
serif"><strong>Username:</strong></font></td>
<td width="81%"><input name="username" type="text" id="username"
value="<?=$_POST['username'];?>"></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-
serif"><strong>Password:</strong></font></td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">
<input type="hidden" name="req" value="validate">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
</form>

-------------------------------------------------------------------------------------
loggedin.php

<?php
include $_SERVER['DOCUMENT_ROOT'].
'/layout.php';

myheader("Now In Logged In!");
include $_SERVER['DOCUMENT_ROOT'].
'/html/loggedin_message.html';
footer();
?>

-------------------------------------------------------------------------------------
Back to top View user's profile Send private message Visit poster's website MSN Messenger
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sun May 30, 2004 3:04 pm    Post subject: Re: PHP header Function - Not Quite Working. Reply with quote

mjjk91,

Before this header() statement, there is a call to myheader("Validate!");. If this function outputs something, any later header() statement won't be effective (and PHP will show a warning.) You must execute header() before any other output (no embedded HTML, no echo statements...)
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
mjjk91
-


Joined: 03 Feb 2004
Posts: 75
Location: Australia

PostPosted: Sat Jun 05, 2004 11:52 am    Post subject: Still Not Working Reply with quote

aprelium,

Thanks for your advice. I took out the myheader("Validate"); function, and its still not working. It still wont re-direct to the loggedin.php page, and its not coming up with any content, that is, no error messages, and no webpage content. So, any ideas on how i can rectify this?

Cheers

Mick Koch
Back to top View user's profile Send private message Visit poster's website MSN Messenger
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sun Jun 06, 2004 2:09 pm    Post subject: Re: Still Not Working Reply with quote

mjjk91,

Please send us your php.ini file and all the files that are related to this script to support@aprelium.com . We'll help you find what's going wrong with these scripts.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
phlatline
-


Joined: 24 Aug 2003
Posts: 6

PostPosted: Mon Jun 07, 2004 4:30 am    Post subject: Reply with quote

I'm very new to PHP but isn't the header function supose to be passed single quotes? header('Location: loggedin.php');
Back to top View user's profile Send private message
iNaNimAtE
-


Joined: 05 Nov 2003
Posts: 2381
Location: Everywhere you're not.

PostPosted: Mon Jun 07, 2004 5:01 am    Post subject: Reply with quote

It doesn't matter.
_________________
Bienvenidos!
Back to top View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
mjjk91
-


Joined: 03 Feb 2004
Posts: 75
Location: Australia

PostPosted: Tue Jun 08, 2004 3:02 am    Post subject: Still Not Working - But Tried Something Reply with quote

G'Day All,

Im still trying to work this problem out. I did some reading, and as people have told me, the header() function cannot be used after an output function, such as echo or print. Referring to the above code in the login.php file, if i was to put the line header("location: /loggedin.php"); right at the start of the file, directly under <?php, the page successfully redirects to the loggedin.php file, but none of the variables are passed from the login.php file. If i was to put the header() line after the include $_SERVER....... line, i get the same blank screen, and no re-direct. So, what does this mean?

Cheers everyone.

Michael Koch
Back to top View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group