Jump to content


setcookie again...


12 replies to this topic

#1 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 09 January 2006 - 07:08 AM

Well, i had to open this new topic, since my first was locked, even though i havent figured it out yet...
this is my first time using ob_start, so im not sure how to use it.
my code right now
***
if(($postlogin == $adminlogin) && ($postpassword == $adminpassword)){
ob_start();
setcookie ("adminlogin", "$postlogin", "3600");
setcookie ("adminpass", "$postpassword", "3600");
ob_end_flush();
}
****
According to php.net, this should work, but it doesnt.
Am i really just that dumb or what?

#2 Eck

    Young Padawan

  • Members
  • Pip
  • 14 posts

Posted 09 January 2006 - 08:51 PM

***
ob_start();
if(($postlogin == $adminlogin) && ($postpassword == $adminpassword)){
setcookie ("adminlogin", "$postlogin", time()+3600);
setcookie ("adminpass", "$postpassword", "time()+3600);
ob_end_flush();
}
****
Always put ob_start(); above all html and php coding.

Edited by Eck, 09 January 2006 - 08:52 PM.


#3 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 20 August 2006 - 11:20 AM

bump,

say i got something like this
<html><head>
<?php
echo 'blabla';
?>
<table></table>
<?php
setcookie();
?>
</html>
Where would i put ob_start(); and where ob_end_flush();???

#4 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 20 August 2006 - 11:24 AM

ob_start() ALWAYS goes at the end of the script and ob_end_flush() always goes a the bottom above ?>

#5 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 20 August 2006 - 03:18 PM

like this?

<html><head>
<?php
echo 'blabla';
?>
<table></table>
<?php
setcookie();
ob_start();
ob_end_flush();
?>
</html>


#6 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 20 August 2006 - 04:00 PM

More like this.
<?php
ob_start();
setcookie();
?>
<html><head>
<?php
echo 'blabla';
?>
<table></table>
</html>
<?php
ob_end_flush();
?>

Edited by Demonslay, 20 August 2006 - 04:01 PM.


#7 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 20 August 2006 - 05:53 PM

If i could set the cookie at the very top of the page i wouldnt need to use ob at all...

I need to set the cookie further down the code, after the headers are already sent

#8 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 20 August 2006 - 06:09 PM

<?php
ob_start();
?>
<html><head>
<?php
echo 'blabla';
setcookie();
?>
<table></table>
</html>
<?php
ob_end_flush();
?>

.....

Edited by .Matt, 20 August 2006 - 06:09 PM.


#9 joe

    Young Padawan

  • Members
  • Pip
  • 115 posts
  • Location:stuck in the middle of cyber space

Posted 21 August 2006 - 05:59 AM

@eck
your are right....
always put ob_start() -> before all html and php code and ob_end() -> after all html and php code.

-Joe-

#10 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 August 2006 - 07:27 PM

View Post.Matt, on Aug 20 2006, 10:24 AM, said:

ob_start() ALWAYS goes at the end of the script and ob_end_flush() always goes a the bottom above ?>

View Post.Matt, on Aug 20 2006, 05:09 PM, said:

.....
You did say ob_start went at the end, not the start :)
But your example is right, and Demonslay, you probably shoulda realized that he was asking about ob_start because set_cookie() is in some included file that doesn't (and/or can't) get called till later ;)

#11 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 21 August 2006 - 07:31 PM

LOL! God damn it!!

*checks when he posted*

Ok, um...10:24am,i am NEVER up that early, so theres a time difference somewhere.Maybe i didnt even post it lol.

Ya sorry for any confusion.

#12 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 23 August 2006 - 05:27 PM

Lol, i switched to a different host with php5 and now it magicly works without the ob ;)
could it have anything to do with the php version?

#13 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 24 August 2006 - 06:07 PM

Maybe your new host has output buffering turned on in their php.ini?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users