header problem

Started on the old forum in November 2010 · view the original in the archive · old links redirect here

7 replies · 416 views · started 16 years ago · 1 min read

4 participants
wap2010v2 Junior · 44 posts #1

hi there friends i am coding my own site and i have got this warning and can not understand what the error is as i used it many times befor

Warning: Cannot modify header information - headers already sent by (output started at C:\******\htdocs\check.php:9) in C:\*******\htdocs\check.php on line 40

this is the part i got problems with

header("location:index.php");
}
else 
{
header("location:index.php?login=1");
}

can some one tell me whats wrong with it please

something else Fellow · 2,296 posts #2

headers already sent

2 headers being used on this page maybe by an included file

wap2010v2 Junior · 44 posts #3

i have tryed a include file but still had problems

something else Fellow · 2,296 posts #4

There is another header above these 2 headers ... find it and remove it 😛

wap2010v2 Junior · 44 posts #5
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tester: Checking Validity. . .</title>
</head>

<body>
<?php
@session_start();
include('administrator/config.php');

$tbl_name="users"; 

$myusername=$_POST['username'];
$mypassword=md5($_POST['password']);

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){

$_SESSION['userlog']=time();
echo "Session set";
header("location:index.php");
}
else 
{
header("location:index.php?login=1");
}
?>
</body>
</html>

this is the page i have having problems on mate

something else Fellow · 2,296 posts #6

all you need is:

<?php 
@session_start(); 
include('administrator/config.php'); 

$tbl_name="users";  

$myusername=$_POST['username']; 
$mypassword=md5($_POST['password']); 

$myusername = stripslashes($myusername); 
$mypassword = stripslashes($mypassword); 
$myusername = mysql_real_escape_string($myusername); 
$mypassword = mysql_real_escape_string($mypassword); 

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; 
$result=mysql_query($sql); 

$count=mysql_num_rows($result); 

if($count==1){ 

$_SESSION['userlog']=time(); 

header("location:index.php"); 
} 
else  
{ 
header("location:index.php?login=1"); 
} 
?>

Added after 6 minutes:

if you wish the page to show the words Session set then you would have to use: <meta http-equiv="refresh" content="10; index.php"> rather than use a header tag

subzero Super moderator Fellow · 3,954 posts #7
<?php 
@session_start(); 
include('administrator/config.php'); 
$tbl_name="users";  
$myusername=$_POST['username']; 
$mypassword=md5($_POST['password']); 
$myusername = stripslashes($myusername); 
$mypassword = stripslashes($mypassword); 
$myusername = mysql_real_escape_string($myusername); 
$mypassword = mysql_real_escape_string($mypassword); 
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; 
$result=mysql_query($sql); 
$count=mysql_num_rows($result); 
if($count==1){ 
$_SESSION['userlog']=time(); 
$msg = "Session set"; 
header("location:index.php"); 
}else{ 
header("location:index.php?login=1"); 
} 
?> 
<!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"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Tester: Checking Validity. . .</title> 
</head> 

<body> 
<?php echo $msg; ?>
</body> 
</html>

Always put @session_start(); before the headers to work right.

Under will some times fail to do its job.

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

CreativityKills Lead · 833 posts #8

Dont use @ to suppress errors. Sucks. Look 4 included files before that line and remove ending ?> also yeah put session_start() up up up.

Also u shud use header_sent()

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close