Posted by Hyshiro Fri 2nd Mar 2007 17:17 - Syntax is PHP - 96 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers
PHP parser reported no syntax errors in this post!
  1.   /* Program: login.php
  2.    * Desc:    Login program for the Members Only section of the pet store.
  3.    *          It provides two options: (1) login using an existing login name and
  4.    *          (2) enter a new login name. Login names and passwords are stored in mysql
  5.    */
  6.      session_start ();
  7.      include("conf.inc");
  8.      switch (@$_GET['do'])
  9.      {
  10.     case "login";
  11.       $connection = mysql_connect($host,$user,$password)
  12.         or die ("Couldn't connect to server.");
  13.       $db = mysql_select_db($database,$connection)
  14.         or die ("Couldn't select database.");
  15.      
  16.       $sql = "SELECT loginName FROM Member
  17.           WHERE loginName='$_POST[fusername]'";
  18.       $result = mysql_query($sql)
  19.         or die("Couldn't execute querry.");
  20.       $num = mysql_num_rows($result);
  21.       if ($num == 1) // login name was found
  22.       {
  23.          $sql = "SELECT loginName FROM Member
  24.              WHERE loginName='$_POST[fusername]'
  25.              AND password=md5('$_POST[fpassword]')";
  26.          $result2 = mysql_query($sql)
  27.             or die("Couldnt execute query 2.");
  28.          $num2 = mysql_num_rows($result2);
  29.          if ($num2 > 0) // password is correct
  30.          {
  31.         $_SESSION['auth']="yes";
  32.         $logname=$_POST['fusername'];
  33.         $_SESSION['logname'] = $logname;
  34.         $today = date("Y-m-d h:m:s");
  35.         $sql = "INSERT INTO Login (loginName,loginTime)
  36.             VALUES ('$logname','$today')";
  37.         mysql_query($sql) or die ("Can't execute query.");
  38.         header("Location: Member_page.php");
  39.          }
  40.          else // password is not correct
  41.          {
  42.         unset($_GET['do']);
  43.         $message="The Login Name, '$_POST[fusername]'
  44.               exists, but you have not entered the correct password, Please try
  45.         again.
    "
    ;
  46.         include("login_form.inc");
  47.          }
  48.     }
  49.     elseif ($num == 0) // login name not found
  50.     {
  51.        unset($_GET['do']);
  52.        $message = "The Login Name you entered does not exist!
  53.                Please try again.
    "
    ;
  54.        include("login_form.inc");
  55.     }
  56.       break;
  57.  
  58.       case "new";
  59.     foreach($_POST as $field => $value)
  60.     {
  61.       if ($field != "fax")
  62.       {
  63.         if ($value == "")
  64.         {
  65.           unset($_GET['do']);
  66.           $message_new = "Required information is missing.
  67.         Please try again.";
  68.           include("login_form.inc");
  69.           exit();
  70.         }
  71.       }
  72.       if (ereg("(Name)",$field))
  73.       {
  74.           if (!ereg("^[A-Za-z' -]{1,50}$",$value))
  75.         {
  76.           unset($_GET['do']);
  77.               $message_new = "$field is not a valid name.
  78.                   Please try again.";
  79.           include('login_form.inc');
  80.           exit();
  81.         }
  82.       }   
  83.       $$field = strip_tags(trim($value));
  84.     } // end foreach
  85.     if (!ereg("^.+@.+\\..+$",$email))
  86.     {
  87.       unset($_GET['do']);
  88.       $message_new = "$email is not a valid email address.
  89.                Please try again.";
  90.       include("login_form.inc");
  91.       exit();
  92.     }
  93.     /* check to see if login name already exists */
  94.     $connection = mysql_connect($host,$user,$password)
  95.         or die ("Couldn't connect to server.");
  96.     $db = mysql_select_db($database,$connection)
  97.         or die ("Couldn't select database.");
  98.     $sql = "SELECT loginName FROM Member
  99.         WHERE loginName='$newname'";
  100.     $result = mysql_query($sql)
  101.         or die("Couldn't execute query.");
  102.     $num = mysql_numrows($result);
  103.     if ($num > 0)
  104.     {
  105.       unset($_GET['do']);
  106.       $message_new = "$newname already used.
  107.                Select another Member ID.";
  108.       include("login_form.inc");
  109.       exit();
  110.     }
  111.     else
  112.     {
  113.       $today = date("Y-m-d");
  114.       $sql = "INSERT INTO Member (loginName,createDate,password,firstName,lastName,
  115.             street,city,state,zip,phone,fax,email) VALUES
  116.           ('$newname','$today',md5('$newpass'),
  117.            '$firstName','$lastName','$street','$city',
  118.            '$state','$zip','$phone','$fax','$email')";
  119.       mysql_query($sql);
  120.       $_SESSION['auth']="yes";
  121.       $_SESSION['logname'] = $newname;
  122.  
  123.     /* send email to new member */
  124.     $emess = "A new Member Account has been setup. ";
  125.     $emess = "Your new Member ID and password are: ";
  126.     $emess = "\n\n\t$newname\n\t$newpass\n\n";
  127.     $emess = "We appreciate your interest BCSO";
  128.     $emess = " at www.bcso.co.uk! \n\n";
  129.     $emess = "If you have any questions or problems,";
  130.     $emess = " email ";
  131.     $ehead="From: ";
  132.     $subj = "Your new Member Account from BCSO";
  133.     $mailsend=mail("$email","$subj","$emess","$ehead");
  134.     header("Location: New_member.php");
  135.     }
  136.       break;
  137.  
  138.       default;
  139.        include("login_form.inc");
  140.     }
  141.   ?>
  142.  
  143.  
  144.  
  145.  
  146.  

PermaLink to this entry https://pastebin.co.uk/11303
Posted by Hyshiro Fri 2nd Mar 2007 17:17 - Syntax is PHP - 96 viewsRun this post in the PHP shell
Download | New Post | Modify | Hide line numbers

 

Comments: 0