0

I'm not particularly PHP savvy though I am able to use it. Unfortunately when I log in with this code it simply redirects me to the page again and doesn't log in. Thing is, I know that it at least works with the MySQL db because I have a register page that works.

I'm running this on a Linux server with PHP5.4 and Apache2.4.

Thanks for any help!

<?php
mysql_connect("localhost", "REDACTED", "REDACTED") or die(mysql_error()); 
mysql_select_db("renew2_mysql") or die(mysql_error()); 
if(isset($_COOKIE['ID_renew_computers'])){ 
    $username = $_COOKIE['ID_renew_computers']; 
    $pass = $_COOKIE['Key_renew_computers'];
    $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
    while($info = mysql_fetch_array( $check ))  
        {
        if ($pass != $info['password']) 
            {
                        }
        else
            {
            header("Location: members.php");
            }
        }
 }
if (isset($_POST['submit'])) { 
    if(!$_POST['username'] | !$_POST['pass']) {
        die('You did not fill in a required field.');
    }
    if (!get_magic_quotes_gpc()) {
        $_POST['email'] = addslashes($_POST['email']);
    }
    $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
$check2 = mysql_num_rows($check);
 if ($check2 == 0) {
        die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
                }
 while($info = mysql_fetch_array( $check ))     
 {
 $_POST['pass'] = stripslashes($_POST['pass']);
    $info['password'] = stripslashes($info['password']);
    $_POST['pass'] = md5($_POST['pass']);
    if ($_POST['pass'] != $info['password']) {
        die('Incorrect password, please try again.');
    }else{ 
     $_POST['username'] = stripslashes($_POST['username']); 
     $hour = time() + 3600; 
 setcookie(ID_renew_computers, $_POST['username'], $hour); 
setcookie(Key_renew_computers, $_POST['pass'], $hour);   
 header("Location: index.php"); 
 } 
 } 
 } 
 else 
{    
?> 
<!DOCTYPE html>
<html>
    <head>
        <title>Renew Computers</title>
        <link href='http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Roboto:100' rel='stylesheet' type='text/css'>
        <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <script>

            function getCookie(c_name){
                var c_value = document.cookie;
                var c_start = c_value.indexOf(" " + c_name + "=");
                if (c_start == -1)
                  {
                  c_start = c_value.indexOf(c_name + "=");
                  }
                if (c_start == -1)
                  {
                  c_value = null;
                  }
                else
                  {
                  c_start = c_value.indexOf("=", c_start) + 1;
                  var c_end = c_value.indexOf(";", c_start);
                  if (c_end == -1)
                  {
                c_end = c_value.length;
                }
                c_value = unescape(c_value.substring(c_start,c_end));
                }
                return c_value;
            }

            function setCookie(c_name,value,time){
                document.cookie = c_name + "=" +escape(value);
            }

            function eraseCookie(cookie_name){
                setCookie(cookie_name,"",-1);
            }

        $(document).ready(function(){
            setInterval(function(){$('#data').focus()},20);

            if(getCookie("err") == 1){
                $('.login-container').css({marginTop:'-60px',opacity:'1'});
                $('.login-container').effect("shake");
                alert("Invalid Card");
                eraseCookie("err");
            }else{
                setTimeout(function(){$('.login-container').animate({marginTop:'-60px',opacity:'1'},500);},500);
            }
        });

        </script>
        <style>
            .background{
                position:fixed;
                top:-100px;
                left:-100px;
                right:-100px;
                bottom:-100px;
                background-image:url('http://renewcomputers.com/data/uploads/renewfront.png');
                -webkit-filter: blur(10px);
                filter: blur(10px);
                background-size:cover;
            }

            .login-container{
                position:fixed;
                top:50%;
                left:50%;
                margin-top:-20px;
                margin-left:-150px;
                height:290px;
                width:300px;
                background-color:#dddddd;
                padding:0;
                opacity:0;
            }

            .login-header{
                width:300px;
                height:50px;
                border-bottom: 1px solid #56af79;
                background-color: #6ac48e;
                font-family: 'Roboto', sans-serif;
                border-bottom: 1px solid #56af79;
                color:white;
                text-decoration:none;
                font-size:22pt;
                line-height:50px;
            }

            .login-header-border{
                border-right: 1px solid #56af79;
                box-shadow: 1px 0 0 rgba(255, 255, 255, 0.3);
            }

            .login-form{
                height:200px;
                width:260px;
                padding:20px;
                font-family: 'Roboto', sans-serif;
            }

            .login-form-input{
            }

            .login-form-button{
            }

             .login-form{
                                height:200px;
                                width:260px;
                                padding:20px;
                                font-family: 'Roboto', sans-serif;
                        }

                        .login-form-input{
                                width:100%;
                                -webkit-appearance: none;
                                appearance: none;
                                display: inline-block;
                                height: 29px;
                                margin: 0;
                                padding: 0 8px;
                                background: #fff;
                                border: 1px solid #c8c8c8;
                                border-top: 1px solid #c0c0c0;
                                -webkit-box-sizing: border-box;
                                -moz-box-sizing: border-box;
                                box-sizing: border-box;
                                -webkit-border-radius: 1px;
                                -moz-border-radius: 1px;
                                border-radius: 1px;
                                font-family: 'Roboto', sans-serif;
                        }

                        .login-form-input:hover{
                                border: 1px solid #b9b9b9;
                                border-top: 1px solid #a0a0a0;
                                -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
                                -moz-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
                                box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
                        }

                        .login-form-input:focus{
                                outline:none;
                        }

                        .login-form-button{
                                height:30px;
                                width:70px;
                                border: 1px solid #3079ed;
                                color: #fff;
                                text-shadow: 0 1px rgba(0,0,0,0.1);
                                background-color: #4d90fe;
                                background-image: -webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#4787ed));
                                background-image: -webkit-linear-gradient(top,#4d90fe,#4787ed);
                                background-image: -moz-linear-gradient(top,#4d90fe,#4787ed);
                                background-image: -ms-linear-gradient(top,#4d90fe,#4787ed);
                                background-image: -o-linear-gradient(top,#4d90fe,#4787ed);
                                background-image: linear-gradient(top,#4d90fe,#4787ed);
                                border-radius:2px;
                        }

                        .login-form-button:hover{
                                border: 1px solid #2f5bb7;
                                color: #fff;
                                text-shadow: 0 1px rgba(0,0,0,0.3);
                                background-color: #357ae8;
                                background-image: -webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#357ae8));
                                background-image: -webkit-linear-gradient(top,#4d90fe,#357ae8);
                                background-image: -moz-linear-gradient(top,#4d90fe,#357ae8);
                                background-image: -ms-linear-gradient(top,#4d90fe,#357ae8);
                                background-image: -o-linear-gradient(top,#4d90fe,#357ae8);
                                background-image: linear-gradient(top,#4d90fe,#357ae8);
                        }
        </style>
    </head>
    <body>
        <div class="background"></div>
        <div id="login" class="login-container">
            <div class="login-header">
                &nbsp;Renew Computers
            </div>
            <div class="login-form">
                <form action="login.php" method="post">
                    Username:<div style="height:10px;"></div>
                    <input type="text" name="username" placeholder="Username" class="login-form-input"/><br /><br />
                    Password:<div style="height:10px;"></div>
                    <input type="password" name="pass" placeholder="Password" class="login-form-input"/><br /><br />
                    <input type="submit" class="login-form-button"/>
                    <input type="hidden" name="type" value="login"/>
                </form>
            </div>
            <!--<div class="login-form">
                <form method="post" action="process.php">
                    <div align="center">Please Swipe Your Card</div><div style="height:10px;"></div>
                    <input type="text" name="data" placeholder="" style="cursor:default;" autocomplete="off" id="data" class="login-form-input"/><br /><br />
                    <input type="submit" class="login-form-button"/>
                    <input type="hidden" name="type" value="login"/>
                </form>
            </div>-->
        </div>
    </body>
</html>
<?php
 }
?>
4

1 回答 1

0

根据评论,我的代码使用了不安全、错误和过时的做法。我选择使用一个更好的更新系统。感谢所有的帮助!

于 2013-09-17T03:28:06.663 回答