Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old July 18th, 2003, 05:11 AM
collins23 collins23 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: kampala uganda
Posts: 19 collins23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old July 18th, 2003, 06:54 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
  #3  
Old July 18th, 2003, 12:34 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
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.

Reply With Quote
  #4  
Old July 18th, 2003, 07:12 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
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:
Originally posted by collins23 [B]
<?

session_start();

if(!session_is_registered('username')){

header( "Location: http://localhost/login.htm" );

}else{


}
?>


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

Reply With Quote
  #5  
Old July 21st, 2003, 01:14 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
For reference, you can also encapsulate the header() function within the exit() function:
PHP Code:
exit( header'blah' ) ); 
__________________
~ 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.




Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > header function problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway