Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Login script that isn't working

Alright here is part of what is in the index.php:
                        <?
               if ($logged == 'yes')
               {
               print_loggedin();
               }
               else
               {
               print_normal();
               }
               function print_normal()
               {
               echo "<h1>Login</h1>";
         
                    echo "<form action=\"login.php\" method=\"post\">";
          echo "User: <input type=\"text\" maxlength=\"12\" size=\"12\" name=\"username\"><br />";
          echo "Pass: <input type=\"password\" maxlength=\"15\" size=\"12\" name=\"password\"><br />";
          echo "<input type=\"hidden\" name=\"logmein\" value=\"1\">";
          echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
          echo "<input type=\"submit\" name=\"Login\" value=\"Login\"></form>";
          echo "<center><a href=\"index.php?action=register\">Sign Up!  </a><a href =\"lostpass.php\">Lost Password?</a></center>";
               echo "</div>";
               echo "<p>";
               echo "</p>";
               }
               
               function print_loggedin()
               { // and here comes the Ecom information
          echo "<h1>User Controls</h1>";
          echo "Hello $username";
          echo "<br>";
          echo "Currently you have: $cartHowMany"; // still needs to be made
          echo "Itmes on your shopping cart.";
          echo "You current balance is: $balance"; // still needs to be made
          echo "<a href=\"control.php\">Control Panel</a> <a href=\"index.php?action=logout\">Log Out</a>";
          }
               ?>

thats all the table functions and what not to change the tables.

and here is the login.php:
<?php
if ($submit = "Login")
{
  mysql_connect("localhost", "*****", "*****") or                
    die ("Could not connect to database");

  mysql_select_db("account") or
    die      ("Could not select database");  

$result=mysql_query("select * from users where username='$username'")
             or die ("cant do it");

while ($row=mysql_fetch_array($result)) {
 if ($row["password"]==$password )
  {
     setcookie("logged","yes",time()+3600);
     setcookie("username","$username",time()+3600);
     echo "<script language=\"javascript\">";
     echo "var jumpURL = \"javascript:history.go(-1)\";";
    echo "function jumpBack() {";
    echo "window.location = jumpURL;";
     echo "}";
     echo "setTimeout(\"jumpBack()\", 3000);";
     echo "</SCRIPT>";
  }
  else
      {
     echo "<script language=\"javascript\">";
     echo "var jumpURL = \"javascript:history.go(-1)\";";
    echo "function jumpBack() {";
    echo "window.location = jumpURL;";
     echo "}";
     echo "setTimeout(\"jumpBack()\", 3000);";
     echo "</SCRIPT>";
    print("Password incorrect!");
   
   }
 }
}
?>


alright so what it is supposed to do is if the username and password watch is set a cookie so that it shows that 'logged' is set to yes and everything, and then go back to the index.php and have the tables changed so it shows what you currently have on your "cart" and what not, just wondering why it is not doing this, the cookie is not being set for some reason anyone see any area's that theres an error in? Thanks.
0
Dl
Asked:
Dl
  • 5
  • 2
  • 2
  • +1
1 Solution
 
carchitectCommented:
if ($submit = "Login")

sorry it is

if ($submit = "Login")

0
 
carchitectCommented:
if ($submit = "Login")

sorry it is

if ($submit == "Login")

0
 
titaniumslugCommented:
umm, the fuctions print_loggedin and print_normal should be placed on the above print_loggedin(); and print_normal();
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DlAuthor Commented:
Alright I made those changes, but its still not working, and the cookies are still not bein set :/
0
 
DlAuthor Commented:
Alright I made those changes, but its still not working, and the cookies are still not bein set :/
0
 
DlAuthor Commented:
hm sry about double post ... not sure why that happend
0
 
DlAuthor Commented:
Any body see any reason for this not to work..? Anyone at all?
0
 
JoeisanerdCommented:
Are you using Windows version of PHP? Check your php.ini file to make that globals are turned on.  Also I assume you are calling the session_start() and session_register() for those variables?
0
 
titaniumslugCommented:
do you get a header error? setcookie() must always be right on top, before everything else.
you could set it to transfer the user to another page which will set the cookies after "if ($row["password"]==$password )"
0
 
DlAuthor Commented:
Thanks alot, I ended up putting the setcookie()'s into the top of another script. Now goes index > login > login2 > index. Thanks alot.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now