Ok - i have read the manual (allthough its not the most clear way).
1) i have a a form and a script for login (ID , passw)
2) i have a menu form and a script which is only allowed after the login form.
note: the login script could as well put out the menu form, so 1) and 2) would be the same.
In 2) the menu, i want to know/use the ID of the guy who logged in.
A cookie would be obvious (or a session).
The problem is the headers - after the login form its too late to set a cookie with the ID for the next form menu, because i have output HTML allready.
And no - i could put it in a GET request like: ?name=donald?id=duck - but then its visible in the adress bar.
how the heck is is possible to use a cookie for that ?? eg. setting a cookie with ID-data after some html jimbo.
it seems that the cookie thing is not well suited for such a login->menu->submenu->etc..
note:
A question might be: how often and when are the header sent. yes - i know at the first
instance of output. but wat if u jump to another html or php with the header(location....) ?
btw: pls don't send suggestions that ure not absolutely sure works.
Goddam cookies - cannot predict id before its too late
Moderator: General Moderators
So what your saying is, you cant set cookies inside the page because you get a header error, saying they have already been sent?
If thats the case, then do what i and alot of other people do and use ob_start() ob_end_flush().
At the very start of the php file put this in:
At the very end of the file put this:
All this does, is allows you to send headers from anywhere on the page.
If thats the case, then do what i and alot of other people do and use ob_start() ob_end_flush().
At the very start of the php file put this in:
Code: Select all
<?php
ob_start();
?>Code: Select all
<?php
ob_end_flush();
?>Sure - but that does'nt work
the testcook.php script accpts only 'ok' as valid login, set a accept cookie
and jumps to getcook.php that test for it as a accepted login, before
any further business...
(remember bout wat i said - only answers that work - pls)
SCRIPT: TESTCOOK.PHP - INPUT FORM FOR LOGIN
SCRIPT: GETCOOK.PHP - RUN ONLY IF THE COOKIE IS SET/VALID
mod_edit: added php tags
the testcook.php script accpts only 'ok' as valid login, set a accept cookie
and jumps to getcook.php that test for it as a accepted login, before
any further business...
(remember bout wat i said - only answers that work - pls)
SCRIPT: TESTCOOK.PHP - INPUT FORM FOR LOGIN
Code: Select all
<?php
ob_start;
if (isset($ID_name) and ($ID_name == 'ok')) { // ok - dude - accepted
setcookie ('LoginID', $ID_name);
header("Location: getcook.php");
}
else { // get id input from form
echo '<HTML>';
echo '<BODY>';
echo '<p align="center"> </p>';
echo '<form method="POST" action="testcook.php">
<div align="center"><div align="center"><center><p>Identifikation<br>
<input type="text" name="ID_name" size="10"><br>
Kodeord<br>
<input type="password" name="ID_passw" size="20"></p>
</center></div><div align="center"><center><p><input type="submit" value="Send" name="B1"></p>
</center></div></div>
</form>';
echo '</BODY>';
echo '</HTML>';
}
ob_end_flush;
?>Code: Select all
<?php
if ($LoginID) // no cookie = no business
{
echo 'Cookie ok ! = ' . $_COOKIE[$LoginID];
}
else
{
echo 'no Cookie !';
}
?>sorry to say it buddy, but your question wasnt exactly crystal clear.
Now, where you have:
What is $LoginID ? That's not a valid variable, change it to:
As far as my php knowledge goes you can't have a variable inside a global variable such as $_COOKIE.
Now, where you have:
Code: Select all
<?php
if ($LoginID) // no cookie = no business
{
echo 'Cookie ok ! = ' . $_COOKIE[$LoginID];
}
else
{
echo 'no Cookie !';
}
?>Code: Select all
<?php
if ( $_COOKIE["LoginID"] )
{
echo "Cookie ok ! = " . $_COOKIE["LoginID"];
}
else
{
echo "No Cookie !";
}
?>