corillo181 Posted November 30, 2006 Share Posted November 30, 2006 whats this error i'm getting.........Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\includes\db.php:2) in C:\wamp\www\phpscripts\check_user.php on line 32 Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/ Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 header('Location: ../home.php');this is what i have in line 32. Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132573 Share on other sites More sharing options...
fert Posted November 30, 2006 Share Posted November 30, 2006 you can't do that headers can only be at the very top of your source code. Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132574 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 but i have the same code in a website and it wokrs fine, but i update the site to a localhost to test somethings and i get that error.. it works on the website but not in the localhost..why is that? Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132575 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 plus it meant with a if statement.. wich is this[code]<?phpif($login_check > 0){ while($row = mysql_fetch_array($sql)){ foreach( $row AS $key => $val ){ $$key = stripslashes( $val ); } // Register some session variables! $_SESSION['username'] = $username; $_SESSION['password'] = $password; $_SESSION['user_id'] = $user_id; $_SESSION['level'] = $level; mysql_query("UPDATE tra_users SET last_login=now() WHERE username='$username'"); header('Location: ../home.php'); }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132576 Share on other sites More sharing options...
bljepp69 Posted November 30, 2006 Share Posted November 30, 2006 it's a good idea to put exit(); after your call to a header like that.Also, make sure you don't have any blank lines or spaces before your "<?php" Those are output to the browser and then you will get that header warning. Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132599 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 no i still get the same warning this is the whole code[code]<?phpsession_start(); // Start Sessioninclude '../includes/db.php';// Conver to simple variables$username = $_POST['username'];$password = $_POST['password'];if((!$username) || (!$password)){ echo "Please enter your password and username! <br />"; include '../htmlforms/login.html'; exit();}// check if the user info validates the db$sql = mysql_query("SELECT * FROM tra_users WHERE username='$username' AND password='$password' AND activated='yes'");$login_check = mysql_num_rows($sql);if($login_check > 0){ while($row = mysql_fetch_array($sql)){ foreach( $row AS $key => $val ){ $$key = stripslashes( $val ); } // Register some session variables! $_SESSION['username'] = $username; $_SESSION['password'] = $password; $_SESSION['user_id'] = $user_id; $_SESSION['level'] = $level; mysql_query("UPDATE tra_users SET last_login=now() WHERE username='$username'");header('Location: ../index.php'); exit(); }} else { echo "You could not be logged in! Either the username and password do not match or you have not validated your membership. Check your email to activate your name or make sure you have your username and password correct!<br /> Please try again!<br />"; include '../htmlforms/login.html';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132610 Share on other sites More sharing options...
JasonLewis Posted November 30, 2006 Share Posted November 30, 2006 wack this at the top:[code=php:0]ob_start();[/code]and again wack this at the bottom of your code:[code=php:0]ob_end_flush();[/code] Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132613 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 even before session_start? Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132616 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 solve that problem but when header sent it to home.php.. the session is broken, even tho i got session_start on top of the page.. Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132620 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 this si what i got in home.php to test the code you just saw and it doesn't work it keeps showing me log in..[code]<?phpsession_start();include_once'header.php';include_once'db.php';if(isset($username)){echo'<a href=mem/memberpage.php>My Info</a> | <a href="phpscript/logout.php">Logout</a>'; }else{ echo'<a href="phpscript/check_user.php">Login</a>'; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132621 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 no clue any one? Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132676 Share on other sites More sharing options...
Daniel0 Posted November 30, 2006 Share Posted November 30, 2006 Try change $username to $_SESSION['username'] Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132679 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 no it wont work, because the $_session is been passed with a variable, so if it dont work with the variable it wont wokr like that ither. Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132689 Share on other sites More sharing options...
Daniel0 Posted November 30, 2006 Share Posted November 30, 2006 What is in the other files? Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132692 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 in the other file are just things to show up if the session variable are passed...but they are not been passed from page to page.i got session start on top of every page, but as soon i'm directed to the next page the session ends.. Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132699 Share on other sites More sharing options...
craygo Posted November 30, 2006 Share Posted November 30, 2006 Read the error. Output was started by the db.php file on line 2. Since you are including another php, db.php, any output from that file is also part of the current page. Check the db.php file for echo statements or anything else that will output to the browser.Ray Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132714 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 on the db.php i only got the connection the the database no headers nothing else, but it wokrs the problem is that my variables ar enot passing to the next page now.. Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132717 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 no idea any one yet? Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132924 Share on other sites More sharing options...
craygo Posted November 30, 2006 Share Posted November 30, 2006 post code for both files, minus passwords and such, so we can help more.Ray Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132928 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 this is the db.[code]<?php$host = 'mysql';$user = 'user';$pass = 'password';$db_name = 'database';$sqlconn = mysql_connect($host,$user,$pass) or die (mysql_error());mysql_select_db($db_name);?>[/code]this is where user get the session[code]<?php/* Check User Script */session_start(); // Start Sessioninclude '../includes/db.php';// Conver to simple variables$username = $_POST['username'];$password = $_POST['password'];if((!$username) || (!$password)){ echo "Please enter your password and username! <br />"; include '../htmlforms/login.html'; exit();}// check if the user info validates the db$sql = mysql_query("SELECT * FROM tra_users WHERE username='$username' AND password='$password' AND activated='yes'");$login_check = mysql_num_rows($sql);if($login_check > 0){ while($row = mysql_fetch_array($sql)){ foreach( $row AS $key => $val ){ $$key = stripslashes( $val ); } // Register some session variables! $_SESSION['username'] = $username; $_SESSION['password'] = $password; $_SESSION['user_id'] = $user_id; $_SESSION['level'] = $level; mysql_query("UPDATE tra_users SET last_login=now() WHERE username='$username'"); header('Location: ../home.php'); }} else { echo "You could not be logged in! Either the username and password do not match or you have not validated your membership. Check your email to activate your name or make sure you have your username and password correct!<br /> Please try again!<br />"; include '../htmlforms/login.html';}?>[/code]and this is the home page.[code]<?phpsession_start();include_once'includes/header.php';include_once'includes/db.php';?> <?php if(isset($username)){}else{?><tr> <td class="menu">::login:: </td> </tr><tr> <td bgcolor="#F0D5A2" class="tdbg"><?php include'htmlforms/login.html';?></td> </tr> <?php }?>[/code] Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132939 Share on other sites More sharing options...
craygo Posted November 30, 2006 Share Posted November 30, 2006 try putting the sql connection in. You might be getting a warning for the connection.[code]mysql_select_db($db_name, $sqlconn) or die(mysql_error());[/code]ray Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132944 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 oh no the connection is no longer my problem.. my problem is the session is not passing to the next php..as you can seen in home i got a if statement for someone who is signed in or is not.. but no matter if they sign in, the state stay false.. the session is not passin along to the next page as it should.. Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132945 Share on other sites More sharing options...
bljepp69 Posted November 30, 2006 Share Posted November 30, 2006 Unless register_globals is on (in your php.ini file), which it likely isn't, you will need to specifically call the session variable "username" like $_SESSION['username']. With register_globals off, $_SESSION['username'] is NOT the same as $username.[code]<?php if($_SESSION['username']){}else{?>[/code] Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132949 Share on other sites More sharing options...
corillo181 Posted November 30, 2006 Author Share Posted November 30, 2006 i tried this now in my home page to see if it worked like that and still it dont..[code]<?php if($_SESSION['username']){echo'<a href=mem/memberpage.php>My Info</a> | <a href="phpscript/logout.php">Logout</a>'; }else{ echo'<a href="phpscript/check_user.php">Login</a>'; } ?></[/code] Link to comment https://forums.phpfreaks.com/topic/28952-header-problem/#findComment-132963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.