Ziph Posted September 11, 2008 Share Posted September 11, 2008 Dear PHP Freaks, Im trying to create a Login system for a little website. To start with im pretty noob at php only started today tho im not stupid so i pretty much understands what everything does tho i dont understand what the code exaclty does. I encountered this error, Warning: Cannot modify header information - headers already sent by (output started at /home/gosuh0/public_html/school/checklogin.php:9) in /home/gosuh0/public_html/school/checklogin.php on line 42 I checked on whitespaces behind my <?php and ?> so thats not it <?php ob_start(); $host="localhost"; // Host name $username="********"; // Mysql username $password="******"; // Mysql password $db_name="********"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $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); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION["myusername"] = $myusername; $_SESSION["mypassword"] = $mypassword; header("location:login_success.php"); //This is the line whats it all about i guess. } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/ Share on other sites More sharing options...
BlueSkyIS Posted September 11, 2008 Share Posted September 11, 2008 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639274 Share on other sites More sharing options...
Ziph Posted September 11, 2008 Author Share Posted September 11, 2008 Yep i checked that but it didnt help me. Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639275 Share on other sites More sharing options...
kenrbnsn Posted September 11, 2008 Share Posted September 11, 2008 What's line 9 of /home/gosuh0/public_html/school/checklogin.php? That's where the output is occurring. Ken Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639276 Share on other sites More sharing options...
Ziph Posted September 11, 2008 Author Share Posted September 11, 2008 <?php but im 100% sure there are no whitespaces because if been checkin that for about 12 hours now. Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639278 Share on other sites More sharing options...
BlueSkyIS Posted September 11, 2008 Share Posted September 11, 2008 so.. what's before line 9? Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639279 Share on other sites More sharing options...
448191 Posted September 11, 2008 Share Posted September 11, 2008 I checked on whitespaces behind my <?php and ?> so thats not it You need to check if there's whitespace BEFORE the opening tag, not 'behind'. Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639280 Share on other sites More sharing options...
Ziph Posted September 11, 2008 Author Share Posted September 11, 2008 1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2<html xmlns="http://www.w3.org/1999/xhtml"> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5<title>Login Check</title> 6</head> 7 8<body> 9<?php ye there are no whitespaces before or behind <?php none behind <body> just 1 enter thats it and even if i remove the enter so line 8 becomes <body><?php the error still apears Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639284 Share on other sites More sharing options...
BlueSkyIS Posted September 11, 2008 Share Posted September 11, 2008 there must be NOTHING before <?php Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639287 Share on other sites More sharing options...
kenrbnsn Posted September 11, 2008 Share Posted September 11, 2008 You can not have ANY OUTPUT before using the header() function. All of that HTML is output. Move your php to before the HTML. Ken Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639288 Share on other sites More sharing options...
BlueSkyIS Posted September 11, 2008 Share Posted September 11, 2008 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html first sentence: i've seen this error pop up time and time again, and the answer is ALWAYS the same. please look here before you post it. the problem is you are outputting to the browser (whitespace included) before sending a header. this is unallowed. Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639290 Share on other sites More sharing options...
Ziph Posted September 11, 2008 Author Share Posted September 11, 2008 ye i do not understand that line. Maybe change it into there may be NOTHING before the <?php instead of whitespace or w/e. =) Anyway tnx allot its fixed now. Link to comment https://forums.phpfreaks.com/topic/123817-cannot-modify-header-information-headers-already-sent-by-problem/#findComment-639293 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.