?
Solved

Login script that isn't working

Posted on 2003-03-07
10
Medium Priority
?
237 Views
Last Modified: 2006-11-17
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
Comment
Question by:Dl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 6

Expert Comment

by:carchitect
ID: 8092876
if ($submit = "Login")

sorry it is

if ($submit = "Login")

0
 
LVL 6

Expert Comment

by:carchitect
ID: 8092878
if ($submit = "Login")

sorry it is

if ($submit == "Login")

0
 

Expert Comment

by:titaniumslug
ID: 8093653
umm, the fuctions print_loggedin and print_normal should be placed on the above print_loggedin(); and print_normal();
0
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 

Author Comment

by:Dl
ID: 8093886
Alright I made those changes, but its still not working, and the cookies are still not bein set :/
0
 

Author Comment

by:Dl
ID: 8093929
Alright I made those changes, but its still not working, and the cookies are still not bein set :/
0
 

Author Comment

by:Dl
ID: 8093931
hm sry about double post ... not sure why that happend
0
 

Author Comment

by:Dl
ID: 8096250
Any body see any reason for this not to work..? Anyone at all?
0
 
LVL 9

Expert Comment

by:Joeisanerd
ID: 8096346
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
 

Accepted Solution

by:
titaniumslug earned 120 total points
ID: 8096381
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
 

Author Comment

by:Dl
ID: 8097399
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question