|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
header function problem
this is the login check i included at the top of my page.
<? session_start(); if(!session_is_registered('username')){ header( "Location: http://localhost/login.htm" ); }else{ } ?> I still had this showing at the top of my page though Warning: Cannot send session cache limiter - headers already sent (output started at /usr/local/httpd/htdocs/start/home.php:2) in /usr/local/httpd/htdocs/start/home.php on line 6 the exit only works when i put it after the code for login.html |
|
#2
|
||||
|
||||
|
I guess a session cookie is sent when you check to see if the variable is registered. Try using ob_start() at the top and ob_flush() (or another of the ob_ functions) at the end to consolidate headers.
|
|
#3
|
|||
|
|||
|
First thing is that you always want to exit the script after a header call, so your code should look like:
Code:
header( "Location: http://localhost/login.htm" ); exit; However, you should try registering your session variables like this: Code:
$_SESSION['username']='myname'; Now you can find out if that session variable exists with this code Code:
session_start();
// we will use the following instead of session_is_registered();
if(!isset($_SESSION['username']))
{
header( "Location: http://localhost/login.htm" );
exit;
}
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#4
|
|||
|
|||
|
Re: header function problem
I agree with Laidbak on the $_SESSIONS issue... You should definitely make use of the superglobals... Newer versions of PHP have "register_globals" turned off, and so using the superglobal arrays ($_POST, $_GET, $_SERVER, $_SESSIONS, etc.) will ensure that you application will be portable among many different versions.
Quote:
You'll want to also make sure that the opening "<?php" is on the FIRST line of your file. If there is any whitespace (blank lines, etc.), you will also receive this error message. HTH!
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#5
|
|||
|
|||
|
For reference, you can also encapsulate the header() function within the exit() function:
PHP Code:
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > header function problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|