Jump to content

Strange login problem.


poofacer

Recommended Posts

My problem revolves around the setting of cookies.

 

My sample website has a simple login with username and password fields.

When I log in, the cookies are set. however when I return to Index.php(main page) or just type localhost (so the index part doesn't show up) it doesn't show me as logged in. The username and password fields should be replaced with the username and different user CP links.

 

Only when I click on a link which uses the "?action=whatever" does the user CP show up. But every time I click on Home, it goes back to the empty fields.

 

Why aren't my cookies being read at the Index.php?

Here is my code. Yes there is some raw HTML above this code. But I don't think this should matter. I also tried the isset function which has the same behaviour.

<?php
$auth=$_COOKIE["auth"];
if($auth == "yes")
{
  echo "// "."<B>".$_COOKIE["username"]." </B>"."//";
  echo "<A HREF=\"javascript:void(0)\" onClick=\"window.open('stats.php','User Stats',config='width=400,height=200,scrollbars=yes')\"> Stats </A> // ";
  echo "<A HREF=\"javascript:void(0)\" onClick=\"window.open('memberlist.php','Members List',config='width=400,height=200,scrollbars=yes')\">Memberlist </A> // ";
  echo " profile //";
  echo "<A HREF=\"logout.php\">[Log out]</A>";
}
else
{
echo "
<FORM method='post' action=\"logged.php\"><B>MEMBER LOGIN:</B>
Username:<INPUT type='text' size='15' maxlength='30' name='username'>
Password:<INPUT type='text' size='15' maxlength='30' name='password'>
<INPUT type='Submit' VALUE='Go'> <A HREF=\"/?act=register\">register</A> <A HREF=\"/?act=forgotpassword\">forgot password?</A>
</FORM>
";
}

 

Here is my code for placing the cookies from a different file(to avoid header errors). This is not the complete code. I omitted by database login information and SQL queries.

<?php
if ($num > 0)
{
  setcookie("auth","yes",time()+3600);   //USER AND PASS ARE CORRECT
  setcookie("username",$user,time()+3600);
  echo "you are logged in.";
}
else
{
  echo "<B>Invalid Username or Password.</B>";
  echo "you are not logged in";
}
?>

 

Thank you for your time.

Link to comment
Share on other sites

Yes ofcourse, or I couldn't log into this site I assume.

 

But now that you mention it, I am using Opera Browser for Windows and it is causing the problem.

 

I also tried in IE 6 and it has a similar problem. It is ok with localhost/index.php but not with localhost itself(doesn't show me logged in).

 

Firefox is the only browser which interprets my code correctly.

 

Another question, I haven't specified the type of HTML coding. ie. Transitional, Strict. I do not have the DOC TYPE header.

 

Could this be tricking the browsers?

 

PS: Firefox is too gangster.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.