PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
JoeCullen
Forum Newbie
Posts: 3 Joined: Wed May 11, 2005 3:51 am
Location: UK
Post
by JoeCullen » Wed May 11, 2005 4:40 am
Ok, I am trying to create a basic login system for my site. I have been testing and without using include files, the code works great. But with the includes I get:
Warning: Cannot modify header information - headers already sent by (output started at /home/joecul41/public_html/index.php:11) in /home/joecul41/public_html/inc_files/login.inc on line 24
This is my code:
Code: Select all
if (isset($_POSTї'Submit']))
{
$username = $_POSTї'username'];
$password = $_POSTї'password'];
$result = mysql_query("e;Select * From users where username='$username'"e;,$link);
if(mysql_num_rows($result)>0)
{
$row = mysql_fetch_array($result, MYSQL_BOTH);
if($password == $rowї"e;password"e;])
{
if($rowї"e;securitylevel"e;] == "e;1"e;)
{
$_POSTї'username'] = "e;username"e;;
$_POSTї'password'] = "e;password"e;;
$msg = "e;Admin Login"e;;
header("e;Location: admin.php"e;);
}
else
{
$msg = "e;Member Login"e;;
}
}
else
{
$msg = "e;Password incorrect"e;;
}
}
else
{
$msg = "e;Username incorrect"e;;
}
}
?>
I know the connection string and everything is correct as the code works fine without the header command. Is there any way to link to another page or open a file without using header()?
As you can probaly tell im new to coding so please any simple solutions would be appreciated.
Thanks in advance.
Revan
Forum Commoner
Posts: 83 Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:
Post
by Revan » Wed May 11, 2005 5:03 am
You probably have already sent data on the page the header is included in.
JoeCullen
Forum Newbie
Posts: 3 Joined: Wed May 11, 2005 3:51 am
Location: UK
Post
by JoeCullen » Wed May 11, 2005 5:21 am
ahh yes i see what im doing wrong now - thanks for that link.
instead of using the header() is there a simple we to redirect?
I noticed on that link there were Java redirects. Does PHP not have a redirect function?
malcolmboston
DevNet Resident
Posts: 1826 Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK
Post
by malcolmboston » Wed May 11, 2005 5:27 am
JoeCullen wrote: Does PHP not have a redirect function?
Yeah, header() function does it, however, as you have noticed when headers have already been sent you cannot use this to redirect.
Go through your source code and re-organise it
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed May 11, 2005 6:56 am
Alternatively, you could use javascript's location.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Wed May 11, 2005 9:20 am
Meta tags.... http-equiv="refresh"....
*yawn*
JoeCullen
Forum Newbie
Posts: 3 Joined: Wed May 11, 2005 3:51 am
Location: UK
Post
by JoeCullen » Wed May 11, 2005 10:27 am
I think the easiest work around is the JavaScript Location command. Its probaly not the neatest but does the job
Thanks once again for all your help and ideas.