473,729 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

header/session start question

Hi.

I am having a few header problems at the moment with a login page. I
don't have my headers at the top of the page where I've learned I need
to have them. However, I also know I'm supposed to have the
session_start() ; at the top of the page as well. So when you have two
things that need to be the first which do you put first? And if I put
one before the other will that cause problems?

Below is a copy of the php from my page. It is the header("Locatio n:
". parts at the bottom in the registering session variables section
that causes the error. Would I just lift out the header locations
parts and put them to the top?

Thanks for any help

John


<?php
session_start() ;
// *** Validate request to login to this site.
//session_start() ;
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting (E_ALL);
?>

<?php require_once('C onnections/conn_newland.ph p'); ?>

<?php

// *** Validate request to login to this site.
$loginFormActio n = $_SERVER['PHP_SELF'];
if (isset($accessc heck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_registe r('PrevUrl');
}

if (isset($_POST['username'])) {
$loginUsername= $_POST['username'];
$password=$_POS T['pwd'];
$MM_fldUserAuth orization = "userGroup" ;
$MM_redirectLog inSuccess = "index.php" ;
$MM_redirectLog inFailed = "login_failed.p hp";
$MM_redirecttoR eferrer = true;
mysql_select_db ($database_conn _newland, $conn_newland);

$LoginRS__query =sprintf("SELEC T username, pwd, userGroup FROM
tbl_users WHERE username='%s' AND pwd='%s'",
get_magic_quote s_gpc() ? $loginUsername :
addslashes($log inUsername), get_magic_quote s_gpc() ? $password :
addslashes($pas sword));

$LoginRS = mysql_query($Lo ginRS__query, $conn_newland) or
die(mysql_error ());
$loginFoundUser = mysql_num_rows( $LoginRS);
if ($loginFoundUse r) {

$loginStrGroup = mysql_result($L oginRS,0,'userG roup');

//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;

//register the session variables
session_registe r("MM_Username" );
session_registe r("MM_UserGroup ");

if (isset($_SESSIO N['PrevUrl']) && true) {
$MM_redirectLog inSuccess = $_SESSION['PrevUrl'];
}
header("Locatio n: ". $MM_redirectLog inSuccess );
}
else {
header("Locatio n: ". $MM_redirectLog inFailed );
}
}
?>

Jul 17 '05 #1
6 3432
John wrote:
I am having a few header problems at the moment with a login page. I
don't have my headers at the top of the page where I've learned I need
to have them. However, I also know I'm supposed to have the
session_start() ; at the top of the page as well. So when you have two
things that need to be the first which do you put first? And if I put
one before the other will that cause problems?


What header problems do you have? Starting with a call to session_start() ,
followed by a header() call shouldn't cause any problems.

Even several header() calls do not cause errors, because headers are send
only when content is displayed or at the end of the script (whatever comes
first):

<?php

// header not send
header("X-Header: Foo");
header("X-Header-Description: Bar");

// headers are send
print "Hello";

// Error because the headers are already sent
header("Locatio n: http://example.com/");
?>

Or:

<?php

// header not send
header("X-Header: Foo");
header("X-Header-Description: Bar");
header("Locatio n: http://example.com/");

// No more lines of code, headers will be send
?>

Even the above examples would work when you instruct PHP to wait sending the
output through output buffering (see http://www.php.net/ob_start).
JW

Jul 17 '05 #2
On Sun, 24 Oct 2004 09:22:26 +0200, A strange species called
"Janwillem Borleffs" <jw@jwscripts.c om> wrote:
What header problems do you have? Starting with a call to session_start() ,
followed by a header() call shouldn't cause any problems.

Even several header() calls do not cause errors, because headers are send
only when content is displayed or at the end of the script (whatever comes
first):

<?php

// header not send
header("X-Header: Foo");
header("X-Header-Description: Bar");

// headers are send
print "Hello";

// Error because the headers are already sent
header("Locatio n: http://example.com/");
?>

Or:

<?php

// header not send
header("X-Header: Foo");
header("X-Header-Description: Bar");
header("Locatio n: http://example.com/");

// No more lines of code, headers will be send
?>

Even the above examples would work when you instruct PHP to wait sending the
output through output buffering (see http://www.php.net/ob_start).
JW


Hi.

I receive the following error:

Warning: Cannot modify header information - headers already sent by
(output started at /home/xxxxx/public_html/newland/login.php:11) in
/home/xxxxx/public_html/newland/login.php on line 55

This is line 55 to 61 below:

header("Locatio n: ". $MM_redirectLog inSuccess );
}
else {
header("Locatio n: ". $MM_redirectLog inFailed );
}
}
?>

Do I just move that to the top then after the session start?

John

<?php
session_start() ;
// *** Validate request to login to this site.
//session_start() ;
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting (E_ALL);
?>

<?php require_once('C onnections/conn_newland.ph p'); ?>

<?php

// *** Validate request to login to this site.
$loginFormActio n = $_SERVER['PHP_SELF'];
if (isset($accessc heck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_registe r('PrevUrl');
}

if (isset($_POST['username'])) {
$loginUsername= $_POST['username'];
$password=$_POS T['pwd'];
$MM_fldUserAuth orization = "userGroup" ;
$MM_redirectLog inSuccess = "index.php" ;
$MM_redirectLog inFailed = "login_failed.p hp";
$MM_redirecttoR eferrer = true;
mysql_select_db ($database_conn _newland, $conn_newland);

$LoginRS__query =sprintf("SELEC T username, pwd, userGroup FROM
tbl_users WHERE username='%s' AND pwd='%s'",
get_magic_quote s_gpc() ? $loginUsername :
addslashes($log inUsername), get_magic_quote s_gpc() ? $password :
addslashes($pas sword));

$LoginRS = mysql_query($Lo ginRS__query, $conn_newland) or
die(mysql_error ());
$loginFoundUser = mysql_num_rows( $LoginRS);
if ($loginFoundUse r) {

$loginStrGroup = mysql_result($L oginRS,0,'userG roup');

//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;

//register the session variables
session_registe r("MM_Username" );
session_registe r("MM_UserGroup ");

if (isset($_SESSIO N['PrevUrl']) && true) {
$MM_redirectLog inSuccess = $_SESSION['PrevUrl'];
}
header("Locatio n: ". $MM_redirectLog inSuccess );
}
else {
header("Locatio n: ". $MM_redirectLog inFailed );
}
}
?>
Jul 17 '05 #3
John <do*@tanion.com > wrote in
news:ho******** *************** *********@4ax.c om:
On Sun, 24 Oct 2004 09:22:26 +0200, A strange species called
"Janwillem Borleffs" <jw@jwscripts.c om> wrote:
What header problems do you have? Starting with a call to
session_start (), followed by a header() call shouldn't cause any
problems.

Even several header() calls do not cause errors, because headers are
send only when content is displayed or at the end of the script
(whatever comes first):

<?php

// header not send
header("X-Header: Foo");
header("X-Header-Description: Bar");

// headers are send
print "Hello";

// Error because the headers are already sent
header("Locatio n: http://example.com/");
?>

Or:

<?php

// header not send
header("X-Header: Foo");
header("X-Header-Description: Bar");
header("Locatio n: http://example.com/");

// No more lines of code, headers will be send
?>

Even the above examples would work when you instruct PHP to wait
sending the output through output buffering (see
http://www.php.net/ob_start).
JW


Hi.

I receive the following error:

Warning: Cannot modify header information - headers already sent by
(output started at /home/xxxxx/public_html/newland/login.php:11) in
/home/xxxxx/public_html/newland/login.php on line 55

This is line 55 to 61 below:

header("Locatio n: ". $MM_redirectLog inSuccess );
}
else {
header("Locatio n: ". $MM_redirectLog inFailed );
}
}
?>

Do I just move that to the top then after the session start?

John

<?php
session_start() ;
// *** Validate request to login to this site.
//session_start() ;
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting (E_ALL);
?>

<?php require_once('C onnections/conn_newland.ph p'); ?>

<?php

// *** Validate request to login to this site.
$loginFormActio n = $_SERVER['PHP_SELF'];
if (isset($accessc heck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_registe r('PrevUrl');
}

if (isset($_POST['username'])) {
$loginUsername= $_POST['username'];
$password=$_POS T['pwd'];
$MM_fldUserAuth orization = "userGroup" ;
$MM_redirectLog inSuccess = "index.php" ;
$MM_redirectLog inFailed = "login_failed.p hp";
$MM_redirecttoR eferrer = true;
mysql_select_db ($database_conn _newland, $conn_newland);

$LoginRS__query =sprintf("SELEC T username, pwd, userGroup FROM
tbl_users WHERE username='%s' AND pwd='%s'",
get_magic_quote s_gpc() ? $loginUsername :
addslashes($log inUsername), get_magic_quote s_gpc() ? $password :
addslashes($pas sword));

$LoginRS = mysql_query($Lo ginRS__query, $conn_newland) or
die(mysql_error ());
$loginFoundUser = mysql_num_rows( $LoginRS);
if ($loginFoundUse r) {

$loginStrGroup = mysql_result($L oginRS,0,'userG roup');

//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;

//register the session variables
session_registe r("MM_Username" );
session_registe r("MM_UserGroup ");

if (isset($_SESSIO N['PrevUrl']) && true) {
$MM_redirectLog inSuccess = $_SESSION['PrevUrl'];
}
header("Locatio n: ". $MM_redirectLog inSuccess );
}
else {
header("Locatio n: ". $MM_redirectLog inFailed );
}
}
?>


whats in your require_once file?
Jul 17 '05 #4
On Sun, 24 Oct 2004 20:39:13 -0000, A strange species called Theo
<in*****@noemai l.com> wrote:
John <do*@tanion.com > wrote in
news:ho******* *************** **********@4ax. com:
On Sun, 24 Oct 2004 09:22:26 +0200, A strange species called
"Janwillem Borleffs" <jw@jwscripts.c om> wrote:
What header problems do you have? Starting with a call to
session_star t(), followed by a header() call shouldn't cause any
problems.

Even several header() calls do not cause errors, because headers are
send only when content is displayed or at the end of the script
(whatever comes first):

<?php

// header not send
header("X-Header: Foo");
header("X-Header-Description: Bar");

// headers are send
print "Hello";

// Error because the headers are already sent
header("Locatio n: http://example.com/");
?>

Or:

<?php

// header not send
header("X-Header: Foo");
header("X-Header-Description: Bar");
header("Locatio n: http://example.com/");

// No more lines of code, headers will be send
?>

Even the above examples would work when you instruct PHP to wait
sending the output through output buffering (see
http://www.php.net/ob_start).
JW


Hi.

I receive the following error:

Warning: Cannot modify header information - headers already sent by
(output started at /home/xxxxx/public_html/newland/login.php:11) in
/home/xxxxx/public_html/newland/login.php on line 55

This is line 55 to 61 below:

header("Locatio n: ". $MM_redirectLog inSuccess );
}
else {
header("Locatio n: ". $MM_redirectLog inFailed );
}
}
?>

Do I just move that to the top then after the session start?

John

<?php
session_start() ;
// *** Validate request to login to this site.
//session_start() ;
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting (E_ALL);
?>

<?php require_once('C onnections/conn_newland.ph p'); ?>

<?php

// *** Validate request to login to this site.
$loginFormActio n = $_SERVER['PHP_SELF'];
if (isset($accessc heck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_registe r('PrevUrl');
}

if (isset($_POST['username'])) {
$loginUsername= $_POST['username'];
$password=$_POS T['pwd'];
$MM_fldUserAuth orization = "userGroup" ;
$MM_redirectLog inSuccess = "index.php" ;
$MM_redirectLog inFailed = "login_failed.p hp";
$MM_redirecttoR eferrer = true;
mysql_select_db ($database_conn _newland, $conn_newland);

$LoginRS__query =sprintf("SELEC T username, pwd, userGroup FROM
tbl_users WHERE username='%s' AND pwd='%s'",
get_magic_quote s_gpc() ? $loginUsername :
addslashes($log inUsername), get_magic_quote s_gpc() ? $password :
addslashes($pas sword));

$LoginRS = mysql_query($Lo ginRS__query, $conn_newland) or
die(mysql_error ());
$loginFoundUser = mysql_num_rows( $LoginRS);
if ($loginFoundUse r) {

$loginStrGroup = mysql_result($L oginRS,0,'userG roup');

//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;

//register the session variables
session_registe r("MM_Username" );
session_registe r("MM_UserGroup ");

if (isset($_SESSIO N['PrevUrl']) && true) {
$MM_redirectLog inSuccess = $_SESSION['PrevUrl'];
}
header("Locatio n: ". $MM_redirectLog inSuccess );
}
else {
header("Locatio n: ". $MM_redirectLog inFailed );
}
}
?>


whats in your require_once file?


That contains a database with a few different tables. One of the
tables has all the usernames and passwords for people who register.
This current page that I'm having these problems with is the login
page.

Cheers

John
Jul 17 '05 #5
John <qu**@duck.co m> wrote in news:r83pn091af pila6kb4kg8uj6k 4bcajijcl@
4ax.com:
That contains a database with a few different tables. One of the
tables has all the usernames and passwords for people who register.
This current page that I'm having these problems with is the login
page.

Cheers

John


unless Im mistaken the line requiring that file is the one it doesnt
like. So maybe something in it is causing the problem.

I use something similar... a correct login redirects to the next page,
and its in a function call. But for it to work the call must be made
before there are any print statements or html code of any kind (not
incluind sprintf, which doesnt output anything). Also, try putting an
exit() after each header, just in case.
Jul 17 '05 #6
I would say the errors are the spaces you introduced and these were output
(Marked with "HERE >" in your code). Once a character is send, which is
HTML, no header can be sent anymore, hence the error when you send the
Location header. You should remove any text outside the PHP tags also in the
required file.
--
René
comunica2.com
Web Hosting, design and translations

<?php
session_start() ;
// *** Validate request to login to this site.
//session_start() ;
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting (E_ALL);
?> HERE > <?php require_once('C onnections/conn_newland.ph p'); ?> HERE >
HERE >
HERE > <?php

// *** Validate request to login to this site.
$loginFormActio n = $_SERVER['PHP_SELF'];
if (isset($accessc heck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_registe r('PrevUrl');
}

if (isset($_POST['username'])) {
$loginUsername= $_POST['username'];
$password=$_POS T['pwd'];
$MM_fldUserAuth orization = "userGroup" ;
$MM_redirectLog inSuccess = "index.php" ;
$MM_redirectLog inFailed = "login_failed.p hp";
$MM_redirecttoR eferrer = true;
mysql_select_db ($database_conn _newland, $conn_newland);

$LoginRS__query =sprintf("SELEC T username, pwd, userGroup FROM
tbl_users WHERE username='%s' AND pwd='%s'",
get_magic_quote s_gpc() ? $loginUsername :
addslashes($log inUsername), get_magic_quote s_gpc() ? $password :
addslashes($pas sword));

$LoginRS = mysql_query($Lo ginRS__query, $conn_newland) or
die(mysql_error ());
$loginFoundUser = mysql_num_rows( $LoginRS);
if ($loginFoundUse r) {

$loginStrGroup = mysql_result($L oginRS,0,'userG roup');

//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;

//register the session variables
session_registe r("MM_Username" );
session_registe r("MM_UserGroup ");

if (isset($_SESSIO N['PrevUrl']) && true) {
$MM_redirectLog inSuccess = $_SESSION['PrevUrl'];
}
header("Locatio n: ". $MM_redirectLog inSuccess );
}
else {
header("Locatio n: ". $MM_redirectLog inFailed );
}
}
?>

Jul 17 '05 #7

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

Similar topics

2
4440
by: Stijn Goris | last post by:
Hi all, I have a question regarding the header function. I send a browser to a certain page (eg first.php ) wich sends no output to the browser. This page sends the browser to another page (eg second.php) with the header("Location:") function. second.php doesn't either send any output to the browser. The browser is then send to another page also with the header() function. Now my problem: I have to send user and password data...
6
3400
by: Lochness | last post by:
I'm hoping someone can help me with this. I've seen and tried various solutions I've seen on the net, but nothing works. Of course it works perfectly on localhost, but when I upload it to the server (1and1.com) it gives errors. The user enters a code, the code is verified, a new one is created and it's supposed to send them to the next page. if (CodeExist($cCode) > 0){ $cNewCode = MakeCode(); $ok = InsertRec($cNewCode);
2
5531
by: Fredrik Olsson | last post by:
I have dynamic library in a DLL. With a standard c header file to it. Writing a simple COM-wrapper in Visual Basic 6 was quite simple, and proves effective in providing my library's functionality to VB and VBScript. Now I want to let the .NET developers have just as much of a breeze, but it has proven not to be quite as easy. I want to write the .net class library in c# and I can not change the original API in anyway as it is a deployed...
23
3645
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 page I don't get any session variable values! BTW, I used a relative location in the Location header, not an absolute URL. The behavior looks like it started another session, but it should not have. Ideas? TIA,
4
10420
by: geshan | last post by:
In php5 I am not able to use include funciton and header("location:""" together please help.
1
2586
by: kgcsinte | last post by:
I hope someone can help with this one. This is a include file that is used to check if a user is logged in before displaying a page. I get this error when any page that references the include page. -----Start error message ----------- Response object error 'ASP 0156 : 80004005' Header Error
6
3990
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public string UID; public string PWD; }
9
3257
by: upendrajpr | last post by:
Hi everybody, I am working with site development with PHP. My problem is I have made a header file of header.inc . I use php function for session start but I when I to to php file for some validation and come to same page the error is come that Header already sent.... "Warning: session_start() : Cannot send session cache limiter - headers already sent ...."
9
2378
by: wizardry | last post by:
hello - if session is started from the same page, and i have another script that needs to access header data with out destorying the session data. a. should i store the header info in variables on the page then access them by the var in the page that needs them? error desc: currently if the session has started and that script is executed it resends the header info which appearantly destroys the session and errors "saying headers...
0
8921
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9284
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9202
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9148
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.