chump2877
06-05-2005, 05:54 PM
I've got the following script that validates a sign-in page for a PHP-driven chat room, then forwards the user to the chat room if everything validates OK:
<?
//file authenticate.php
include "connect.php";
if (isset($_POST['submit'])) // name of submit button
{
$chatter=$_POST['chatter'];
$password=$_POST['password'];
$password=md5($password);
$query = "select * from ch_chatters where chatter='$chatter' and password='$password'";
$result = mysql_query($query) or die("not queried") ;
$isAuth = false; //set to false originally
while($row = mysql_fetch_array($result))
{
$isAuth=true;
session_start();
$_SESSION['chatter']=$chatter;
}
print "
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html lang=en>
<head>
<link rel='stylesheet' href='style.css' type='text/css'>
<title>Media Moguls - Virtual Classroom</title>
<meta name = 'description' content = 'Media Moguls provides a seamless integration of media design and current technology. We are an agency that offers copy writing, web page development, computer hardware sales, and print design at competitive prices.'>
<meta name = 'keywords' content = 'business writing, copy writing, web copy writing, web site copy writing, ad copy writing, professional copy writing, write copy, advertisement copy writing, business writing, copy writing, web copy writing, web site copy writing, ad copy writing, professional copy writing, write copy, advertisement copy writing'>
<script language='JavaScript' src='http://www.mediamogulsweb.com/js_menu2.js'></script>
<script language='JavaScript' src='http://www.mediamogulsweb.com/mm_menu.js'></script>
</head>
<body bgcolor='#D1C9BE' background='http://www.mediamogulsweb.com/gradient_back_main.jpg' style='background-repeat: repeat-x; margin-top: 0'>
<center><table border='0' cellpadding='0' cellspacing='0' width='800'><tr><td>
<script language='JavaScript1.2'>mmLoadMenus();</script>
<!-- toolbar contents -->
<center>
<table border='0' cellpadding='0' cellspacing='0' width='800'>
<tr>
<td><img src='http://www.mediamogulsweb.com/top_image.jpg'></td>
</tr>
<tr>
<td>
<table border='0' cellpadding='0' cellspacing='0' style='margin-top: 0'>
<tr>
<td><img src='http://www.mediamogulsweb.com/top_image_left.jpg'></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927223844_0,0,23,null,'image1')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/home.jpg' name='image1' border='0' id='image1'></a></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927224326_0,0,23,null,'image2')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/products.jpg' name='image2' border='0' id='image2'></a></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927224655_0,0,23,null,'image3')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/services.jpg' name='image3' border='0' id='image3'></a></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927224907_0,0,23,null,'image4')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/news.jpg' name='image4' border='0' id='image4'></a></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927230259_0,0,23,null,'image5')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/contact.jpg' name='image5' border='0' id='image5'></a></td>
<td><img src='http://www.mediamogulsweb.com/top_image_right.jpg'></td>
</table></td>
</tr>
</table>
</center></tr>
<tr>
<td><img src='http://www.mediamogulsweb.com/top_image_bottom.jpg'></td>
</tr>
</table>
</center>
<!-- end toolbar contents -->
<h3><center>The Virtual Classroom</center></h3>
<br>
";
if($isAuth==true)
{
$check="SELECT * from ch_online where sessionname='$chatter'";
$check2=mysql_query($check) or die("2");
$check3=mysql_fetch_array($check2);
if(!$check3)
{
$day=date('U');
$s="INSERT into ch_online (sessionname, time) values ('$chatter','$day' )";
$s2=mysql_query($s) or die("not queried");
}
header("location: index.php" );
}
else
{
print "<center><div style='background-color:#ffffff;padding:15px;width:50%;border:outset'><span style='color:#FF0000'>Warning:</span> Username or password entered incorrectly.<br><br><i>Please use your browser's \"Back\" button to return to the form and fix any errors.</i></div></center>
<br><br><br><br><br><br><br><br>
<div style='width:112px;height:41px;clear:both;margin:auto'><img src='http://www.mediamogulsweb.com/logo2.jpg' alt=''></div>
<br>
<center>
<table border='0' cellpadding='0' cellspacing='0' width='472'><tr>
<td width='20'></td>
<td style='background-image:url(http://www.mediamogulsweb.com/links_gradient2.jpg);width:432px;height:25px'>
<center>
<A class=b HREF='http://www.mediamogulsweb.com/index.shtml'>Home</A> | <A class=b HREF='http://www.mediamogulsweb.com/catalog.shtml'>Catalog</A> | <A class=b HREF='http://www.mediamogulsweb.com/quote.shtml'>Quote</A> | <A class=b HREF='http://www.mediamogulsweb.com/industry_news.php'>News</A> | <A class=b HREF='http://www.mediamogulsweb.com/contact.shtml'>Contact</A>
</center>
</td>
<td width='20'></td>
</tr></table>
</center>
<br><center><font size='1'>Media Moguls ©2005. All rights reserved.</font></center>
</td></tr></table></center>
</body>
</html>";
}
}
?>
I get the following errors when a correct username and password is submitted on the sign-in page:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/httpd/vhosts/mediamogulsweb.com/httpdocs/chat_script/authenticate.php:2) in /home/httpd/vhosts/mediamogulsweb.com/httpdocs/chat_script/authenticate.php on line 19
Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/mediamogulsweb.com/httpdocs/chat_script/authenticate.php:2) in /home/httpd/vhosts/mediamogulsweb.com/httpdocs/chat_script/authenticate.php on line 103
I've fiddled around with my session and header statements, but I can't seem to get rid of the error messages. Instead of seeing those error messages, I should be forwarded to the chat room (index.php).
If you want to see the page and error messages for yourself, go to the following page: http://www.mediamogulsweb.com/chat_script/login.php. Type in "tester" for the username AND the password, and you can view the resulting chaos.
Thanks in advance for any help with this. :)
<?
//file authenticate.php
include "connect.php";
if (isset($_POST['submit'])) // name of submit button
{
$chatter=$_POST['chatter'];
$password=$_POST['password'];
$password=md5($password);
$query = "select * from ch_chatters where chatter='$chatter' and password='$password'";
$result = mysql_query($query) or die("not queried") ;
$isAuth = false; //set to false originally
while($row = mysql_fetch_array($result))
{
$isAuth=true;
session_start();
$_SESSION['chatter']=$chatter;
}
print "
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html lang=en>
<head>
<link rel='stylesheet' href='style.css' type='text/css'>
<title>Media Moguls - Virtual Classroom</title>
<meta name = 'description' content = 'Media Moguls provides a seamless integration of media design and current technology. We are an agency that offers copy writing, web page development, computer hardware sales, and print design at competitive prices.'>
<meta name = 'keywords' content = 'business writing, copy writing, web copy writing, web site copy writing, ad copy writing, professional copy writing, write copy, advertisement copy writing, business writing, copy writing, web copy writing, web site copy writing, ad copy writing, professional copy writing, write copy, advertisement copy writing'>
<script language='JavaScript' src='http://www.mediamogulsweb.com/js_menu2.js'></script>
<script language='JavaScript' src='http://www.mediamogulsweb.com/mm_menu.js'></script>
</head>
<body bgcolor='#D1C9BE' background='http://www.mediamogulsweb.com/gradient_back_main.jpg' style='background-repeat: repeat-x; margin-top: 0'>
<center><table border='0' cellpadding='0' cellspacing='0' width='800'><tr><td>
<script language='JavaScript1.2'>mmLoadMenus();</script>
<!-- toolbar contents -->
<center>
<table border='0' cellpadding='0' cellspacing='0' width='800'>
<tr>
<td><img src='http://www.mediamogulsweb.com/top_image.jpg'></td>
</tr>
<tr>
<td>
<table border='0' cellpadding='0' cellspacing='0' style='margin-top: 0'>
<tr>
<td><img src='http://www.mediamogulsweb.com/top_image_left.jpg'></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927223844_0,0,23,null,'image1')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/home.jpg' name='image1' border='0' id='image1'></a></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927224326_0,0,23,null,'image2')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/products.jpg' name='image2' border='0' id='image2'></a></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927224655_0,0,23,null,'image3')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/services.jpg' name='image3' border='0' id='image3'></a></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927224907_0,0,23,null,'image4')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/news.jpg' name='image4' border='0' id='image4'></a></td>
<td><a href='javascript:;' onMouseOver='MM_showMenu(window.mm_menu_0927230259_0,0,23,null,'image5')' onMouseOut='MM_startTimeout();'><img src='http://www.mediamogulsweb.com/contact.jpg' name='image5' border='0' id='image5'></a></td>
<td><img src='http://www.mediamogulsweb.com/top_image_right.jpg'></td>
</table></td>
</tr>
</table>
</center></tr>
<tr>
<td><img src='http://www.mediamogulsweb.com/top_image_bottom.jpg'></td>
</tr>
</table>
</center>
<!-- end toolbar contents -->
<h3><center>The Virtual Classroom</center></h3>
<br>
";
if($isAuth==true)
{
$check="SELECT * from ch_online where sessionname='$chatter'";
$check2=mysql_query($check) or die("2");
$check3=mysql_fetch_array($check2);
if(!$check3)
{
$day=date('U');
$s="INSERT into ch_online (sessionname, time) values ('$chatter','$day' )";
$s2=mysql_query($s) or die("not queried");
}
header("location: index.php" );
}
else
{
print "<center><div style='background-color:#ffffff;padding:15px;width:50%;border:outset'><span style='color:#FF0000'>Warning:</span> Username or password entered incorrectly.<br><br><i>Please use your browser's \"Back\" button to return to the form and fix any errors.</i></div></center>
<br><br><br><br><br><br><br><br>
<div style='width:112px;height:41px;clear:both;margin:auto'><img src='http://www.mediamogulsweb.com/logo2.jpg' alt=''></div>
<br>
<center>
<table border='0' cellpadding='0' cellspacing='0' width='472'><tr>
<td width='20'></td>
<td style='background-image:url(http://www.mediamogulsweb.com/links_gradient2.jpg);width:432px;height:25px'>
<center>
<A class=b HREF='http://www.mediamogulsweb.com/index.shtml'>Home</A> | <A class=b HREF='http://www.mediamogulsweb.com/catalog.shtml'>Catalog</A> | <A class=b HREF='http://www.mediamogulsweb.com/quote.shtml'>Quote</A> | <A class=b HREF='http://www.mediamogulsweb.com/industry_news.php'>News</A> | <A class=b HREF='http://www.mediamogulsweb.com/contact.shtml'>Contact</A>
</center>
</td>
<td width='20'></td>
</tr></table>
</center>
<br><center><font size='1'>Media Moguls ©2005. All rights reserved.</font></center>
</td></tr></table></center>
</body>
</html>";
}
}
?>
I get the following errors when a correct username and password is submitted on the sign-in page:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/httpd/vhosts/mediamogulsweb.com/httpdocs/chat_script/authenticate.php:2) in /home/httpd/vhosts/mediamogulsweb.com/httpdocs/chat_script/authenticate.php on line 19
Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/mediamogulsweb.com/httpdocs/chat_script/authenticate.php:2) in /home/httpd/vhosts/mediamogulsweb.com/httpdocs/chat_script/authenticate.php on line 103
I've fiddled around with my session and header statements, but I can't seem to get rid of the error messages. Instead of seeing those error messages, I should be forwarded to the chat room (index.php).
If you want to see the page and error messages for yourself, go to the following page: http://www.mediamogulsweb.com/chat_script/login.php. Type in "tester" for the username AND the password, and you can view the resulting chaos.
Thanks in advance for any help with this. :)