Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stupid cookies!

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Argh..I'm having a pain in the arse of a time with cookies! For some reason, including a file before creating a cookie is causing problems. At the moment I have;

Code:
function do_login() {

   // require here...otherwise we get hassle from the cookie stuff :(
   require_once("settings.inc.php");
   global $login_username, $login_password, $admin_username, $admin_password;


   if ($login_username == $admin_username && $login_password == $admin_password) {

   setcookie(SETUSERNAME, $login_username);
   setcookie(SETPASSWORD, $login_password);

   // rerquire here...otherwise we get hassle from the cookie stuff :(

   show_logged_in("0");

 } else {

   normal_error("The username/password combination you entered does not seem to be valid. Please check and try again.");

 }

}

And the error I KEEP getting is;

Warning: Cannot add header information - headers already sent by (output started at /home/ace-clipart.com/public_html/directory/cgi/banner/admin/settings.inc.php:43) in /home/ace-clipart.com/public_html/directory/cgi/banner/admin/admin.php on line 94

Warning: Cannot add header information - headers already sent by (output started at /home/ace-clipart.com/public_html/directory/cgi/banner/admin/settings.inc.php:43) in /home/ace-clipart.com/public_html/directory/cgi/banner/admin/admin.php on line 95


Note that line 94 and 95 are the setcookie() lines.

Any help you guys can offer would be much appreciated :

Thanks

Andy
 
As I understand it you can only set cookies before you send or recieve any other info for the page, that being so, you need to set the cookie variables and pass them to a new page where you can then set the cookie before you do anything else

----------------------new page--------------
<?php
setcookie();
setcookie();
//everything else you ever desired below this line ***************************************
Party on, dudes!
[cannon]
 
My guess is that whatever is on line 43 in settings.inc.php is echoing text. If this text is necessary, then you will have to set your cookies beforehand or buffer the output until after the cookies have been set...
 
Yeah, problem is that all settings.inc.php is, simply holds a list of variables in &quot;&quot;'s. So I can not see where it is coming from. Also, it only goes it to line 24 :|

Any more ideas?

Thanks

Andy
 
make sure you don't have any blank lines above your first <?php tag or it won't work either.
--------top of page

<?php // will not work

--------top of page
<?php // will be happier ***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top