PDA

View Full Version : wats rong with this? +rep



Jamie.
03-05-2007, 04:34 PM
setcookie("id", $user['id'],time()+(60*60*24*5), "/", "");
setcookie("pass", $user['password'],time()+(60*60*24*5), "/", "");
It keeps coming up with...
http://www.uploadz.co.uk/560hmm.png

Edited by Lµke (Forum Moderator): Thread Moved from Website Designing. Please post in the correct section next time, Thanks :).

Drompo
03-05-2007, 04:38 PM
Your trying to set something after the head tags.

Jamie.
03-05-2007, 04:41 PM
hmm? wat <Head> or...? Lmao.. i was ok at coding until cape across this :| i was like *** noob php= me :|

Florx
03-05-2007, 05:20 PM
Use sessions instead = Faster = Easier = Safer

Blob
03-05-2007, 05:23 PM
You need to put that at the top of the page ontop of everything else (the php script, your not allowed html above it if you are setting cookies)

Drompo
03-05-2007, 05:25 PM
You need to put that at the top of the page ontop of everything else (the php script, your not allowed html above it if you are setting cookies)

Thats basicly what i said,

Off Topic: You gone back to your old name Blob, Yey!

Jamie.
03-05-2007, 05:52 PM
so blob, your saying like this for example your NOT allowed;

<head><title>Blah</title></head><html><font face="verdana" size="1"> bla bla </font></html>
<?
echo("hello world");
?>

Like that so wud it be?
<?
echo("hello world");
?>
<head><title>Blah</title></head><html><font face="verdana" size="1"> bla bla </font></html>

for example, echo being the cookies bit :p


Use sessions instead = Faster = Easier = Safer
YEH SHUP K THATS NOT TEH QUESTIon and i broke my shift key "/

Drompo
03-05-2007, 05:56 PM
Yes thats right.

Jamie.
03-05-2007, 05:57 PM
lemme try :P

look for edit...... n i say if works or not :)

EDIT: Wow cheers, ill bare this in mind next time ;) thanks blob omgz ryan umm and reina crap keeper anywho :P

Drompo
03-05-2007, 06:07 PM
lemme try :P

look for edit...... n i say if works or not :)

EDIT: Wow cheers, ill bare this in mind next time ;) thanks blob omgz ryan umm and reina crap keeper anywho :P

Your Obviously A Chelsea Fan

Jamie.
03-05-2007, 06:12 PM
man utd lol :) reina, can u help me with another error :P

Drompo
03-05-2007, 06:13 PM
Ok, Pm me your msn if you like

Blob
04-05-2007, 03:53 PM
so blob, your saying like this for example your NOT allowed;

<head><title>Blah</title></head><html><font face="verdana" size="1"> bla bla </font></html>
<?
echo("hello world");
?>

Like that so wud it be?
<?
echo("hello world");
?>
<head><title>Blah</title></head><html><font face="verdana" size="1"> bla bla </font></html>

for example, echo being the cookies bit :p


YEH SHUP K THATS NOT TEH QUESTIon and i broke my shift key "/

Im not saying that, Im saying this:

If you have anything that needs a header, like starting sessions cookies or just using header(""); you need to make sure its at the top of the page.

E.g.


<html>
<head>
<title>Hello</title>
</head>
<body>
<?php header("Location: index.php"); ?>
</body>
</html>

That would produce a header error, so you have to use:



<?php header("Location: index.php"); ?>
<html>
<head>
<title>Hello</title>
</head>
<body>
</body>
</html>

So its at the top of the page

But if its at the top of the page, you can still have php above it, like:



<?php
$string = "insert";
$stupid = "idiots";
$in = "here";
header("Location: index.php");
?>
<html>
<head>
<title>Hello</title>
</head>
<body>
</body>
</html>

Get what I mean?

timROGERS
04-05-2007, 05:29 PM
You can only send headers before you've sent any output to the browser.

Florx
12-05-2007, 07:53 PM
AHH Thanks for that - it clears it up.

is that the same for session_start() and ob_start or whatever they are :)?

daftmoo
12-05-2007, 08:18 PM
Yep - cookies and sessions must be intiated before any output is sent to the browser, otherwise you better have a raincoat on, because there will be errors.

Want to hide these adverts? Register an account for free!