473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Include and Header(Location: ) not working together

In php5 I am not able to use include funciton and header("location:"""
together please help.

Aug 27 '06 #1
4 10401
*** geshan escribió/wrote (26 Aug 2006 22:36:45 -0700):
In php5 I am not able to use include funciton and header("location:"""
together please help.
In what sense aren't you able? I mean, you just type the code as usual,
don't you? What prevents you from doing so?

I'll make an exercise of fortune telling. You've upgraded to PHP 5 and you
are using the default settings in php.ini, where display_errors is
disabled. Enable it this way:

display_errors = On
error_reporting = E_ALL

When you do so, the PHP interpreter will say you cannot insert a header
because output already started. You cannot print anything into the page
before using the header() function. That includes blank lines outside the
<?php ?tags.
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 27 '06 #2

these are the errors i get,

Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
D:\Xampp\xampp\htdocs\GM_PHP\includes\conn1.php:11 ) in
D:\Xampp\xampp\htdocs\GM_PHP\login_process.php on line 2

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
D:\Xampp\xampp\htdocs\GM_PHP\includes\conn1.php:11 ) in
D:\Xampp\xampp\htdocs\GM_PHP\login_process.php on line 2

Warning: Cannot modify header information - headers already sent by
(output started at D:\Xampp\xampp\htdocs\GM_PHP\includes\conn1.php:11 )
in D:\Xampp\xampp\htdocs\GM_PHP\login_process.php on line 38

i'm using xampp with php, Apache 2.2 and mysql 4.01

I'm posting the login_process.php file here, it is made for a login
system plesae help:

<?php
session_start();
include("includes/conn1.php");
?>
<?php
if(isset($_POST['Submit']))
{
$username=$_POST['txtusername'];
$password_frm=$_POST['txtpassword'];
//$users_in='';

if(!empty($username) && !empty($password_frm))
{

$sql="SELECT password FROM tbl_users WHERE user_name = '$username'
and user_status=1";
$users_in=mysql_query($sql) or die(mysql_error());
$pass_db=mysql_result($users_in,0,0);

/*while($user_valid=mysql_fetch_array($users_in))
{
//echo $user_valid['password'];
$pass_db= $user_valid['password'];
}

//still left to validate password
//while(
//$user_data=mysql_fetch_array($users_in);
//extract($user_in); */

if($pass_db==$password_frm)
{
//set session
$_SESSION['logged_in_username']=$username;
$_SESSION['user_status']="valid";

header("Location:logged_in.php");
//echo "logged in.";
}
else
{
header("Location:login.php?msg=pwerror");
//echo "Invalid PW.";
//echo $users_in['password'];
}
}
else
{
header("Location:login.php?msg=blank");
//echo "Error. blank";
}
}
else
{
header("Location:login.php?msg=illegal");
//echo "Empty not allowed.";
}
?>

The Code of conn1.php

<?php

$con=mysql_connect("localhost","root","") or die(mysql_error());

mysql_select_db("gesDB",$con);

//echo 'conncection succesful.';

?>

I need help. Please Help Fast

Aug 28 '06 #3
geshan wrote:
these are the errors i get,

Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
D:\Xampp\xampp\htdocs\GM_PHP\includes\conn1.php:11 ) in
D:\Xampp\xampp\htdocs\GM_PHP\login_process.php on line 2

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
D:\Xampp\xampp\htdocs\GM_PHP\includes\conn1.php:11 ) in
D:\Xampp\xampp\htdocs\GM_PHP\login_process.php on line 2

Warning: Cannot modify header information - headers already sent by
(output started at D:\Xampp\xampp\htdocs\GM_PHP\includes\conn1.php:11 )
in D:\Xampp\xampp\htdocs\GM_PHP\login_process.php on line 38
<code snipped>
>
I need help. Please Help Fast
Just like it said - line 11 of includes\conn1.php is causing output to
be sent to the browser. This forces the headers to be sent to the
browser. session_start() must be called before ANY output is sent to
the browser.

The output could be from an echo or print statement, for instance. Or
it could be just whitespace outside of the <?php ... ?brackets. Any
output will cause the headers to be sent.

The only confusing factor here is that you don't include
include\conn1.php until after the session_start() command. It looks
like this isn't your exact code, or perhaps your login_process.php is
itself included in another file.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 28 '06 #4

Dear Jerry,
Thank you very much but i solved the problem. The problem was n
conn1.php where i have left three blank lines after the code that was
causing the errors.

Geshan.

Aug 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jock | last post by:
A script i'm working on is behaving real strange. It is more or less the same as dozens of others that work aok. Info is posted from one script to another, the second script does some work...
6
by: Filth | last post by:
Hi this is probably very easy to sort but I want to do the following:- header( "Location: subscribe_form.php?name='.$_GET.'&email='.$_GET.'"); but this pulls up the error:- Parse error:...
10
by: Margaret MacDonald | last post by:
I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about. I have some code that does some processing and then does a...
11
by: pinbot | last post by:
As far as I know, http headers should not work after content has been written. This is how my production box is working, but for some reason on my dev box I was getting away with a location header...
23
by: lwoods | last post by:
I am trying to pass some info to another page on my site. I set "session_start()" in page 1, assign a session variable to a value, then execute a "header('Location: ....')." But on the target...
2
by: Ladbroke | last post by:
Hiya, got a little prob with the syntax for header ( ' Location .... with variable). Usually examples are given with a complete URL, like: ..... header( 'Location: login/testsite/start.php'...
6
by: P-Rage | last post by:
Hello everyone, I was wondering what could possibly cause Internet Explorer 6 to loop a page usging a header(Location:) statement. For example, a page called 'page1.php': if((isset($_POST))...
8
by: php newbie | last post by:
I have a simple php page in which I use header("Location: http://www.example.com/"); to redirect the user to another php page. The php script works on my local machine but when I upload it to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.