Copy link to clipboard
Copied
This is the error i recieve when I use the log in system of my website. The session ID is correctly sent to the database and the form is processed.
Although, when it comes to redirecting to the logged in homepage this error appears. I have tested this exact script with no problems in my computers local host.
WHen uploaded online and tested tho the error appears. Please help!:
Warning: Cannot modify header information - headers already sent by (output started at /home/gr/public_html/members_login_handle.php:6) in /home/gr/public_html/members_login_handle.php on line 97.
The coding for the members_login_handle.php which processes my members_login.php form to login is below:
<?php
session_start();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<script type="text/javascript">
<!--
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
// -->
function disSel(target){
if (typeof target.onselectstart!="undefined")
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined")
target.style.MozUserSelect="none"
else
target.onmousedown=function(){return false}
target.style.cursor = "default"
}
</script>
<script type="text/javascript">
window.onload = function () {
document.body.onselectstart = function () {
return false;
}
document.body.ondragstart = function () {
return false;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Staff Login</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="seo" -->
<meta name="Description" content="" />
<meta name="Keywords" content="" />
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="../stylesheets/main_styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<div id="header">
<div id="logo"><a href="../index.php"><img src="../images/logo.gif" width="156" height="148" border="0" alt="img" title="Logo"/></a></div>
Great Linford
<br />Primary School</div>
<div id="motto"><div id="myarea"><a href="../html_files/student_area.html" >My Area</a></div>
Be proud to do the "Right Thing"
<a href="../html_files/student_area.html"><img src="../images/star.gif" width="89" height="89" border="0" alt="img"/></a></div>
<div id="menu">
<ul>
<li><a href="../index.php" accesskey="1">Homepage</a></li>
<li><a href="../html_files/school_tour.html" accesskey="2">School Tour</a></li>
<li><a href="../html_files/calendar.php" accesskey="3">Calendar</a></li>
<li><a href="../html_files/newsletter.php" accesskey="4">Newsletter</a></li>
<li><a href="../html_files/events.html" accesskey="5">Events</a></li>
<li><a href="../html_files/parents.html" accesskey="6">Parents</a></li>
<li><a href="../html_files/staff.html" accesskey="7">Staff</a></li>
<li><a href="../html_files/contact_us.html" accesskey="8">Contact Us</a></li></ul>
</div>
<div id="content"><!-- InstanceBeginEditable name="page_content" -->
<?php
include_once('members_login_con.php');
$id = $_REQUEST['id'];
$pwd = md5($_REQUEST['pwd']);
if(preg_replace('/[a-zA-Z0-9]/', '', $id)){
echo "Invalid entry"; echo "<br>";
echo "<a href=\"members_login.php\"><br />Please try again</a>.";
}
else{
$check=mysql_query("SELECT * FROM users WHERE email = '".$id."' AND pwd = '".$pwd."'");
$row_num=mysql_num_rows($check);
if($row_num < 1){
echo "The user name and/or password has been entered incorrectly.";
echo "<br />";
echo "<br />";
echo "Please <a href=\"members_login.php\">Try again</a>.";
}else{
$_SESSION['members'] = md5($_REQUEST['number']);
$members = $_SESSION['members'];
$_SESSION['id']=$id;
$check = mysql_query("SELECT*FROM $table WHERE id= '".$id."' AND pwd = '".$pwd."'");
$row_num = mysql_num_rows($check);
if($row_num < 1){
mysql_query("INSERT INTO $table (session,id,pwd) VALUES ('$members','$id','$pwd')");
header('location:"members_area.php?sess='.$URLsession.'"');
}else{
echo "You are not authorised to log in concurrent sessions";
echo "<br />";
echo "<a href=\members_login.php\">Try again</a>";
}
}
}
?>
Thanks and can't wait to hear back with responses. Been trying to fix it for days...
If any additional infomation is required I would be happy to provide it.
Louise
I meant that you need to move the entire block of server side code above the head tags.
Copy link to clipboard
Copied
You are sending a header to command to redirect the page after you have already output all of your html. You can't do that. You must issue this command before any characters or whitespace are sent to the browser. Move this test and redirect code up to the top of the page.
Copy link to clipboard
Copied
Thanksyou for your response, but I do not understand how to structure this. Because it is within an else statment, it is taking into account the scripting before it. If I move this to the top wouldn't it automatically redirect without taking into account the if/or statments that I want it to question?
And if so, where would it be placed above?
If possible, would you maybe be able to copy, edit and repaste the script?? This woould help me sooo much!!!! Or if it'd be easier to work by instructions that would help a lot too
❤️ ❤️
Thanks again you your response
Other responses highly welcomed!
Louise
Copy link to clipboard
Copied
I meant that you need to move the entire block of server side code above the head tags.
Copy link to clipboard
Copied
How much of it's server side code??
Seriously not sure what i'm doing?
If that means all the php coding, i've tried moving that all to where: 'session ();' is, with the same errors.
I may be doing this wrong though...
Could you show me please by repasting the code?
I am really grateful for your help.
Louise
Copy link to clipboard
Copied
He is saying change it to this:
<?phpsession_start();include_once('members_login_con.php');
$id = $_REQUEST['id'];
$pwd = md5($_REQUEST['pwd']);
if(preg_replace('/[a-zA-Z0-9]/', '', $id)){
echo "Invalid entry"; echo "<br>";
echo "<a href=\"members_login.php\"><br />Please try again</a>.";
}
else{
$check=mysql_query("SELECT * FROM users WHERE email = '".$id."' AND pwd = '".$pwd."'");
$row_num=mysql_num_rows($check);
if($row_num < 1){
echo "The user name and/or password has been entered incorrectly.";
echo "<br />";
echo "<br />";
echo "Please <a href=\"members_login.php\">Try again</a>.";
}else{
$_SESSION['members'] = md5($_REQUEST['number']);
$members = $_SESSION['members'];
$_SESSION['id']=$id;
$check = mysql_query("SELECT*FROM $table WHERE id= '".$id."' AND pwd = '".$pwd."'");
$row_num = mysql_num_rows($check);
if($row_num < 1){
mysql_query("INSERT INTO $table (session,id,pwd) VALUES ('$members','$id','$pwd')");
header('location:"members_area.php?sess='.$URLsession.'"');
}else{
echo "You are not authorised to log in concurrent sessions";
echo "<br />";
echo "<a href=\members_login.php\">Try again</a>";
}
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<script type="text/javascript">
<!--
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
// -->
function disSel(target){
if (typeof target.onselectstart!="undefined")
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined")
target.style.MozUserSelect="none"
else
target.onmousedown=function(){return false}
target.style.cursor = "default"
}
</script>
<script type="text/javascript">
window.onload = function () {
document.body.onselectstart = function () {
return false;
}
document.body.ondragstart = function () {
return false;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Staff Login</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="seo" -->
<meta name="Description" content="" />
<meta name="Keywords" content="" />
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="../stylesheets/main_styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<div id="header">
<div id="logo"><a href="../index.php"><img src="../images/logo.gif" width="156" height="148" border="0" alt="img" title="Logo"/></a></div>
Great Linford
<br />Primary School</div>
<div id="motto"><div id="myarea"><a href="../html_files/student_area.html" >My Area</a></div>
Be proud to do the "Right Thing"
<a href="../html_files/student_area.html"><img src="../images/star.gif" width="89" height="89" border="0" alt="img"/></a></div>
<div id="menu">
<ul>
<li><a href="../index.php" accesskey="1">Homepage</a></li>
<li><a href="../html_files/school_tour.html" accesskey="2">School Tour</a></li>
<li><a href="../html_files/calendar.php" accesskey="3">Calendar</a></li>
<li><a href="../html_files/newsletter.php" accesskey="4">Newsletter</a></li>
<li><a href="../html_files/events.html" accesskey="5">Events</a></li>
<li><a href="../html_files/parents.html" accesskey="6">Parents</a></li>
<li><a href="../html_files/staff.html" accesskey="7">Staff</a></li>
<li><a href="../html_files/contact_us.html" accesskey="8">Contact Us</a></li></ul>
</div>
<div id="content"><!-- InstanceBeginEditable name="page_content" -->
Your server side code is the php. Give that a try, see what it does for you.
Gary
Copy link to clipboard
Copied
Thanks guys, worked it out now
Find more inspiration, events, and resources on the new Adobe Community
Explore Now