当前位置: 首页 > 知识库问答 >
问题:

单击我的域中的php[复制]

衡建中
2023-03-14

当我点击我的网站时,我的网站出现了问题,它只是下载,甚至没有加载到下一页。我能做什么?我应该换什么?我只是一个html和php的新手,顺便说一句,我点击的文件是我制作的一个php文件,当我点击那个php文件时,它并没有指向下载文件的下一页。我想知道是否有人在这里帮助我,提前感谢可能帮助我的人。这只是为了我的项目。http://itweb.bitballoon.com/这是一个网站,当我点击该标志并注册时,它将下载php文件。我不知道如何解决这个问题。我已经在youtube和google上搜索过了。我看不出一个答案。请帮帮我,谢谢。

登记代码。php

<?php
    ob_start();
    session_start();
    if( isset($_SESSION['user'])!="" ){
        header("Location: home.php");
    }
    include_once 'dbconnect.php';

    $error = false;

    if ( isset($_POST['btn-signup']) ) {

        // clean user inputs to prevent sql injections
        $firstname = trim($_POST['firstname']);
        $firstname = strip_tags($firstname);
        $firstname = htmlspecialchars($firstname);

        $middlename = trim($_POST['middlename']);
        $middlename = strip_tags($middlename);
        $middlename = htmlspecialchars($middlename);

        $lastname = trim($_POST['lastname']);
        $lastname = strip_tags($lastname);
        $lastname = htmlspecialchars($lastname);

        $student_number = trim($_POST['student_number']);
        $student_number = strip_tags($student_number);
        $student_number = htmlspecialchars($student_number);

        $course = $_POST['course'];

        $pass = trim($_POST['pass']);
        $pass = strip_tags($pass);
        $pass = htmlspecialchars($pass);

        // basic name validation
        if (empty($firstname)) {
            $error = true;
            $firstnameError = "Please enter your firstname.";
        } else if (strlen($firstname) < 2) {
            $error = true;
            $firstnameError = "Firstname must have atleat 2 characters.";
        } else if (!preg_match("/^[a-zA-Z ]+$/",$firstname)) {
            $error = true;
            $firstnameError = "Firstname must not contain numbers or special characters.";
        }

        if (!empty($middlename) && !preg_match("/^[a-zA-Z ]+$/",$middlename)) {
            $error = true;
            $middlenameError = "Middlename must not contain numbers or special characters.";
        }

        if (empty($lastname)) {
            $error = true;
            $lastnameError = "Please enter your lastname.";
        } else if (strlen($lastname) < 2) {
            $error = true;
            $lastnameError = "Lastname must have atleat 2 characters.";
        } else if (!preg_match("/^[a-zA-Z ]+$/",$lastname)) {
            $error = true;
            $lastnameError = "Lastname must not contain numbers or special characters.";
        }

        if (empty($course)) {
            $error = true;
            $courseError = "Please select a course.";
        }

        if (empty($student_number)) {
            $error = true;
            $student_numberError = "Please enter your student number.";
        } else if (!(strlen($student_number) >= 12 && strlen($student_number) <= 13)) {
            $error = true;
            $student_numberError = "Student number must have atleat 12 characters.";
        } else if (!preg_match("/^PM-[0-9]{2}-[0-9]{4,5}-[AB]$/", $student_number)) {
            $error = true;
            $student_numberError = "Invalid student number format.";
        } else {
            //check if student number exists
            $result = mysql_query("SELECT * FROM users WHERE student_number = '$student_number'");
            $rowCount = mysql_num_rows($result);

            if ($rowCount == 1) {
                $error = true;
                $student_numberError = "Student number is already taken.";
            }
        }

        // password validation
        if (empty($pass)){
            $error = true;
            $passError = "Please enter password.";
        } else if(strlen($pass) < 6) {
            $error = true;
            $passError = "Password must have atleast 6 characters.";
        }

        // password encrypt using SHA256();
        $password = hash('sha256', $pass);

        // if there's no error, continue to signup
        if( !$error ) {         
            $query = "INSERT INTO users(student_number,userPass,user_role,firstname,middlename,lastname,course) VALUES('$student_number','$password',2,'$firstname','$middlename','$lastname',$course)";
            $res = mysql_query($query);

            if ($res) {
                $errTyp = "success";
                $errMSG = "Successfully registered, you may login now.";
                unset($firstname);
                unset($middlename);
                unset($lastname);
                unset($course);
                unset($student_number);
                unset($pass);
            } else {
                $errTyp = "danger";
                $errMSG = "Something went wrong, try again later...";   
            }   
        }
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Coding Cage - Login & Registration System</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css" type="text/css"  />
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="assets/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#course').change(function () {
            if ($(this).val() == '') {
                $(this).css('color', '#999');
            }
            else {
                $(this).css('color', '#000');
            }
            $('option').css('color', '#000');
        });
        $('#course').trigger('change');
    });
</script>
</head>
<body>
<div class="container">

    <div id="login-form">
    <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">

        <div class="col-md-12">

            <div class="form-group">
                <h2 class="">Sign Up.</h2>
            </div>

            <div class="form-group">
                <hr />
            </div>

            <?php
            if ( isset($errMSG) ) {

                ?>
                <div class="form-group">
                <div class="alert alert-<?php echo ($errTyp=="success") ? "success" : $errTyp; ?>">
                <span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
                </div>
                </div>
                <?php
            }
            ?>

            <div class="form-group">
                <div class="input-group ">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                    <input type="text" name="firstname" class="form-control" placeholder="Firstname" maxlength="50" value="<?php echo $firstname ?>" />
                </div>
                <span class="text-danger"><?php echo $firstnameError; ?></span>
            </div>

            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                    <input type="text" name="middlename" class="form-control" placeholder="Middlename" maxlength="50" value="<?php echo $middlename ?>" />
                </div>
                <span class="text-danger"><?php echo $middlenameError; ?></span>
            </div>

            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                    <input type="text" name="lastname" class="form-control" placeholder="Lastname" maxlength="50" value="<?php echo $lastname ?>" />
                </div>
                <span class="text-danger"><?php echo $lastnameError; ?></span>
            </div>

            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-book"></span></span>
                    <select id="course" name="course" class="form-control">
                        <option <?php echo $course == "1" ? "selected" : "" ?> value="1">BSIT</option>
                        <option <?php echo $course == "2" ? "selected" : "" ?> value="2">BSBA</option>
                        <option <?php echo $course == "3" ? "selected" : "" ?> value="3">BSTM</option>
                        <option <?php echo $course == "4" ? "selected" : "" ?> value="4">BSHRM</option>
                        <option <?php echo $course == "5" ? "selected" : "" ?> value="5">BSN</option>
                        <option <?php echo $course == "6" ? "selected" : "" ?> value="6">BSC</option>
                        <option <?php echo $course == "7" ? "selected" : "" ?> value="7">BSA</option>
                        <option <?php echo $course == "8" ? "selected" : "" ?> value="8">BSE</option>
                        <option <?php echo $course == "9" ? "selected" : "" ?> value="9">ABMC</option>
                        <option <?php echo $course == "10" ? "selected" : "" ?> value="10">BSP</option>
                        <option <?php echo $course == "11" ? "selected" : "" ?> value="11">BAPA</option>
                    </select>
                </div>
                <span class="text-danger"><?php echo $courseError; ?></span>
            </div>

            <div class="form-group">
                <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                <input type="text" name="student_number" class="form-control" placeholder="Student Number" maxlength="50" value="<?php echo $student_number ?>" />
                </div>
                <span class="text-danger"><?php echo $student_numberError; ?></span>
            </div>

            <div class="form-group">
                <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                <input type="password" name="pass" class="form-control" placeholder="Password" maxlength="15" />
                </div>
                <span class="text-danger"><?php echo $passError; ?></span>
            </div>

            <div class="form-group">
                <hr />
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-block btn-primary" name="btn-signup">Sign Up</button>
            </div>

            <div class="form-group">
                <hr />
            </div>

            <div class="form-group">
                <a href="Login.php">Sign in Here...</a>
            </div>

        </div>

    </form>
    </div>  

</div>
</body>
</html>
<?php ob_end_flush(); ?>

登录代码:

<?php
    ob_start();
    session_start();
    require_once 'dbconnect.php';


    if ( isset($_SESSION['user'])!="" ) {
        header("Location: home.php");
        exit;
    }

    $error = false;

    if( isset($_POST['btn-login']) ) {  

        // prevent sql injections/ clear user invalid inputs
        $student_number = trim($_POST['student_number']);
        $student_number = strip_tags($student_number);
        $student_number = htmlspecialchars($student_number);

        $pass = trim($_POST['pass']);
        $pass = strip_tags($pass);
        $pass = htmlspecialchars($pass);
        // prevent sql injections / clear user invalid inputs

        if(empty($student_number)){
            $error = true;
            $student_number_Error = "Please enter your student number.";
        }

        if(empty($pass)){
            $error = true;
            $passError = "Please enter your password.";
        }

        // if there's no error, continue to login
        if (!$error) {
            $password = hash('sha256', $pass); // password hashing using SHA256

            $res=mysql_query("SELECT student_number, userPass, user_role, firstname, middlename, lastname, course FROM users WHERE student_number = '$student_number'");
            $row=mysql_fetch_array($res);
            $count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row

            if( $count == 1 && $row['userPass']==$password ) {
                $_SESSION['user'] = $row['student_number'];
                header("Location: home.php");
                echo $_GET['id'];
            } else {
                $errMSG = "Incorrect Credentials, Try again...";
            }

        }

    }
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Coding Cage - Login & Registration System</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css" type="text/css"  />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>

<div class="container">

    <div id="login-form">
    <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">

        <div class="col-md-12">

            <div class="form-group">
                <h2 class="">Sign In.</h2>
            </div>

            <div class="form-group">
                <hr />
            </div>

            <?php
            if ( isset($errMSG) ) {

                ?>
                <div class="form-group">
                <div class="alert alert-danger">
                <span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
                </div>
                </div>
                <?php
            }
            ?>

            <div class="form-group">
                <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
                <input type="text" name="student_number" class="form-control" placeholder="Student Number" value="<?php echo $student_number; function a(){$student_number=$idc;}?>" maxlength="15" />

                </div>

                <span class="text-danger"><?php echo $student_number_Error; ?></span>
            </div>

            <div class="form-group">
                <div class="input-group">
                <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
                <input type="password" name="pass" class="form-control" placeholder="Password" maxlength="30" />
                </div>
                <span class="text-danger"><?php echo $passError; ?></span>
            </div>

            <div class="form-group">
                <hr />
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-block btn-primary" name="btn-login">Sign In</button>
            </div>

            <div class="form-group">
                <hr />
            </div>

            <div class="form-group">
                <a href="register.php">Sign Up Here...</a>
            </div>

        </div>

    </form>
    </div>  

</div>

</body>
</html>
<?php ob_end_flush(); ?>

错误消息是:致命错误:未捕获错误:调用未定义函数mysql_connect() /storage/ssd5/266/3359266 /public_html/dbconnect.php:11堆栈跟踪:#0 /storage/ssd5/266/3359266 /public_html/login.php(4):require_once()#1{main}抛出 /storage/ssd5/266/3359266 /public_html/dbconnect.php第11行

共有1个答案

李锦
2023-03-14

您需要检查网站托管服务器是否支持PHP。检查服务器中是否配置正确。

 类似资料:
  • 任何帮助都将得到承认。

  • 问题内容: 我有一个简单的代码,单击链接即可打开一个新窗口。但是在执行脚本时,单击相当于双击同一元素,并打开2个窗口。 我正在使用InternetExplorer驱动程序 问题答案: 当你一起工作 , 用 ,您可以考虑通过传递以下配置属性 类别: :由于InternetExplorerDriver仅适用于Windows,因此它尝试使用所谓的“本机”或OS级事件在浏览器中执行鼠标和键盘操作。这与对相

  • 我在pygame中为点击事件制作了按钮,但存在一个问题。当我单击鼠标按钮并在按钮边界之间移动鼠标时,单击事件会重复自身。我只想单击一下,直到松开鼠标按钮。我该怎么做?

  • 问题内容: 我正在尝试将数据从表单发送到php文件,以便可以将其存储在数据库中,但是无法正常工作… 表单的代码与php文件不在同一服务器上,因为表单将在移动应用程序上。 html php文件 谢谢!!! 问题答案: 在PHP文件的开头添加以下内容: 有关跨域策略的更多信息,请参见此处。

  • 在我的应用程序中,我有一个按钮。单击和双击按钮后,将执行单独的操作。我该怎么做?谢谢