|
Posted by Gernot Frisch on 03/09/06 10:47
"jukka" <ikaros@REMOVEMEsci.fi> schrieb im Newsbeitrag
news:dumprd$chi$1@phys-news4.kolumbus.fi...
> Gernot Frisch wrote:
>> I tried cookies. I enter good password and get "checking for
>> cookies" message. Then I press "Continue", and get the "Enter
>> Password" message.
>> What's wrong with my code?
>> I use Firefox. Cookies only from original domains. Forums remember
>> me.
>>
>>
>>
>>
>> // edit.php - file
>>
>> <?php
>>
>>
>> // If cookie posted and correct, set it
>> if(!isset($_COOKIE['glbasic_admin']) )
>> {
>> if($_POST['glbasic_admin'] == $password)
>> {
>> if(!setcookie('glbasic_admin', $_POST['glbasic_admin']))
>> {
>> echo('Fatal! Cant set cookie!?');
>> }
>> }
>> }
>>
>> // No cookie set
>> if(!isset($_COOKIE['glbasic_admin']) )
>> {
>> // but posted correct/incorrect
>> if($_POST['glbasic_admin'] == $password)
>> {
>> echo ('<html><body>Checking if cookies enabled...<br>'.
>> '<a
>> href="edit.php?lang="'.$_GET['lang'].'">Continue</a>');
>> exit();
>> }
>> else if(isset($_POST['glbasic_admin']))
>> {
>> $Content=AddContent('Wrong Password', 'Please try re-typing the
>> password again.', true);
>> }
>> }
>>
>>
>> echo 'Cookie: '.$_COOKIE['glbasic_admin'].'pw:'.$password;
>>
>> // wron password? Have user enter one
>> if($_COOKIE['glbasic_admin'] != $password)
>> {
>> echo('<html><body>Enter the admin password and enable cookies to
>> proceed.'.
>> '<br><form method="post"
>> action="edit.php?lang="'.$_GET['lang'].'<input type="text"
>> name="glbasic_admin" >'.
>> '<br><input type="submit" name="password" value="Login">'.
>> '</form>');
>> exit();
>> }
>>
>> ?>
>>
>>
>>
>>
>>
>
> Do you have the if(!isset($_COOKIE['glbasic_admin']) ) twice on
> purpose?
Yes. It works now - I had the $password in an include file, which I
included too late <Doh!>
Now it works good.
Enter Password,
If correct display message, store cookie, write link for page-reload
If cookie set, display admin panel.
This way I checked both: password and acceptance of cookies.
Here's my code:
<?php
$password = 'KungFu';
if(!isset($_COOKIE['glbasic_admin']) )
{
if($_POST['glbasic_admin'] == $password)
{
if(!setcookie('glbasic_admin', $_POST['glbasic_admin']))
{
echo('Fatal! Cant set cookie!?');
}
}
}
include('config.php'); // functions like "AddContent($topic, $body)"
and "WritePageOut($title, $content)"
$site = $_GET['site'];
if(!isset($_COOKIE['glbasic_admin']) )
{
if($_POST['glbasic_admin'] == $password)
{
$body=AddContent('Password Correct', 'Checking if cookies
enabled...<br><a
href="edit.php?lang="'.$_GET['lang'].'&site='.$site.'">Continue</a>');
WritePageOut('Site Admin', '', $body);
exit();
}
else if(isset($_POST['glbasic_admin']))
{
$Content=AddContent('Wrong Password', 'Please try re-typing the
password again.', true);
}
}
if($_COOKIE['glbasic_admin'] != $password)
{
$body= 'Enter the admin password and enable cookies to proceed.'.
'<br><form method="post"
action="edit.php?lang='.$_GET['lang'].'&site='.$site.'"><input
type="text" name="glbasic_admin" >'.
'<br><input type="submit" name="password" value="Login">'.
'</form>';
WritePageOut('Site Admin', '', $Content . AddContent('Enter
password', $body));
exit();
}
Navigation:
[Reply to this message]
|