草庐IT

php - 重定向 PHP

coder 2024-04-11 原文

<分区>

如何从一个 PHP 页面重定向到另一个页面?

</head>

<body>
    <!-- Home -->
    <div data-role="page" id="page1">
        <div data-theme="a" data-role="header">
            <a data-role="button" data-theme="d" href="login.html" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                        Back
                    </a>
            <a data-role="button" href="index.html" data-icon="home" data-iconpos="right" data-theme="d" class="ui-btn-right">
                     Home  
                    </a>
            <h3>
                Login Process
            </h3>
        </div>
        <div data-role="content">

            <?php
    // takes the variables from action script and assigns them php variables names
    $user = $_POST ['username'];
    $pass = $_POST ['password'];

    // if there is a user name and password
    if ($user && $pass)
    {
        // connect to server
        mysql_connect("localhost", "", "") or die(mysql_error());
        //select database
        mysql_select_db("") or die(mysql_error());

        //Create a query that selects all data from the PATIENT table where the username and password match
        $query = "SELECT * FROM Patient WHERE Username = '$user' AND Password = '$pass'";

        //executes query on the database
        $result = mysql_query ($query) or die ("didn't query");
        //this selects the results as rows

        $num = mysql_num_rows ($result);
        //if there is only 1 result returned than the data is ok 
        if ($num == 1)
        {
            //sends back a data of "Success"
            echo "Successful Login";
            $row=mysql_fetch_array($result);
            $_SESSION['Name'] = $row['Name'];
            $_SESSION['Address'] = $row['Address'];
        }
        else
        {
            //sends back a message of "failed"
            echo "Unsuccessful Login";
        }
    }

    ?>
        </div>
    </div>
</body>

</html>

因此,当用户登录时,会将他们带到上面显示的页面。我需要它做的是,如果登录成功,我需要它重定向到另一个 PHP 页面。


login.php

<?php
    // takes the variables from action script and assigns them php variables names
    $user = $_POST ['username'];
    $pass = $_POST ['password'];
    $error = '';

    // if there is a user name and password
    if ($user && $pass)
    {
        // connect to server
        mysql_connect("localhost", "", "") or die(mysql_error());
        //select database
        mysql_select_db("") or die(mysql_error());

        //Create a query that selects all data from the PATIENT table where the username and password match
        $query = "SELECT * FROM Patient WHERE Username = '$user' AND Password = '$pass'";

        //executes query on the database
        $result = mysql_query ($query) or die ("didn't query");
        //this selects the results as rows

        $num = mysql_num_rows ($result);
        //if there is only 1 result returned than the data is ok 
       if ($num == 1)
    {
    header("Location: http://helios.hud.ac.uk/u101010/PHP/details1.php");
    }
            //sends back a data of "Success"
            $return_message =  "Successful Login";
            $row=mysql_fetch_array($result);
            $_SESSION['Name'] = $row['Name'];
            $_SESSION['Address'] = $row['Address'];
        }
        else
        {
            //sends back a message of "failed"
            $return_message = echo "Unsuccessful Login";
        }
    }
    <html>
        <head>
            <meta charset="utf-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            <meta name="apple-mobile-web-app-capable" content="yes" />
            <meta name="apple-mobile-web-app-status-bar-style" content="black" />
            <title>
            </title>
            <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
            <link rel="stylesheet" href="my.css" />
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
            </script>
            <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
            </script>
            <script src="my.js">
            </script>
            <!-- User-generated css -->
            <style>
            </style>
            <!-- User-generated js -->
            <script>
                try {

        $(function() {

        });

      } catch (error) {
        console.error("Your javascript has an error: " + error);
      }
            </script>

    ?>
    </head>

    <body>
        <!-- Home -->
        <div data-role="page" id="page1">
            <div data-theme="a" data-role="header">
                <a data-role="button" data-theme="d" href="login.html" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                        Back
                    </a>
                <a data-role="button" href="index.html" data-icon="home" data-iconpos="right" data-theme="d" class="ui-btn-right">
                     Home  
                    </a>
                <h3>
                    Login Process
                </h3>
            </div>
            <div data-role="content">

                <?php echo $return_message; ?>

            </div>
        </div>
    </body>

    </html>

Details1.php

<!DOCTYPE html>
<?php
    session_start();
    ?>
    <html>

    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <title>
        </title>
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <link rel="stylesheet" href="my.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
        </script>
        <script src="my.js">
        </script>
        <!-- User-generated css -->
        <style>
        </style>
        <!-- User-generated js -->
        <script>
            try {

                $(function() {

                });

            } catch (error) {
                console.error("Your javascript has an error: " + error);
            }
        </script>
    </head>

    <body>
        <!-- Home -->
        <div data-role="page" id="page1">
            <div data-theme="a" data-role="header">
                <a data-role="button" data-theme="c" href="menu.html" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                        Main Menu
                        </a>
                <h3>
                    Your details
                </h3>


            </div>
            <div data-role="content">
                Name:
                <?php echo $_SESSION['Name'];?>
                <br /> Address:
                <?php echo $_SESSION['Address'];?>



            </div>
    </body>

    </html>

details.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>
    </title>
    <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <link rel="stylesheet" href="my.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>
    <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
    </script>
    <script src="my.js">
    </script>
    <!-- User-generated css -->
    <style>
    </style>
    <!-- User-generated js -->
    <script>
        try {

            $(function() {

            });

        } catch (error) {
            console.error("Your javascript has an error: " + error);
        }
    </script>
</head>

<body>
    <!-- Home -->
    <div data-role="page" id="page1">
        <div data-theme="a" data-role="header">
            <a data-role="button" data-theme="c" href="menu.html" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                        Main Menu
                        </a>
            <h3>
                Your details
            </h3>
        </div>
        <form name="form1" method="post" action="details1.php">
            <strong>Details</strong>
            <br />
            <br /> Name: <input type="text" name "Name" />
            <br /> Address: <input type="text" name="Address" />
            <br />
            <input type="submit" name="Submit" value="Book appointment" />
            <br />
            <input type="submit" name="Submit" value="Cancel appointment" />
        </form>

    </div>
</body>

</html>

login.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>
    </title>
    <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <link rel="stylesheet" href="my.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
    </script>
    <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
    </script>
    <script src="my.js">
    </script>
    <!-- User-generated css -->
    <style>
    </style>
    <!-- User-generated js -->
    <script>
        try {

            $(function() {

            });

        } catch (error) {
            console.error("Your javascript has an error: " + error);
        }
    </script>
</head>

<body>
    <!-- Home -->
    <div data-role="page" id="page1">
        <div data-theme="a" data-role="header">
            <a data-role="button" data-theme="d" href="login.html" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                        Back
                    </a>
            <a data-role="button" href="index.html" data-icon="home" data-iconpos="right" data-theme="d" class="ui-btn-right">
                     Home  
                    </a>
            <h3>
                Login
            </h3>
        </div>
        <div data-role="content">
            <h4>
                Enter login details below:
            </h4>

            <form name="form1" method="post" action="login.php">
                <strong>Patient Login </strong>
                <br />
                <br /> Username: <input name="username" type="text" id="username" />
                <br /> Password: <input name="password" type="password" id="password" />
                <br />
                <br />
                <br />
                <input type="submit" name="Submit" value="Login" />
            </form>
            <br />
            <div data-role="content">
                <h4>
                    Please ensure your username and password are kept secure.
                </h4>

                <br />
            </div>
        </div>
</body>

</html>

有关php - 重定向 PHP的更多相关文章

  1. ruby - 将 spawn() 的标准输出/标准错误重定向到 Ruby 中的字符串 - 2

    我想使用spawn(针对多个并发子进程)在Ruby中执行一个外部进程,并将标准输出或标准错误收集到一个字符串中,其方式类似于使用Python的子进程Popen.communicate()可以完成的操作。我尝试将:out/:err重定向到一个新的StringIO对象,但这会生成一个ArgumentError,并且临时重新定义$stdxxx会混淆子进程的输出。 最佳答案 如果你不喜欢popen,这是我的方法:r,w=IO.pipepid=Process.spawn(command,:out=>w,:err=>[:child,:out])

  2. ruby-on-rails - 这个 C 和 PHP 程序员如何学习 Ruby 和 Rails? - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它

  3. ruby-on-rails - 条件重定向的最佳方式? - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。使用Railsv2.1,假设您有一个可从多个位置访问的Controller的操作。例如,在Rails应用程序中,您有一个链接可以从两个不同的View编辑用户,一个在用户索引View中,另一个在另一个View中(比方说从每个页面上的导航栏)。我想知道根据用户点击的链接将用户重定向回正确位置的最佳方法是什么。例如:示例1:列出所有用户点击列表中用户的“编辑”

  4. ruby-on-rails - 当 AJAX 调用在 Ruby on Rails 中失败时重定向到 500 页 - 2

    我正在使用一个用RubyonRails构建的应用程序,目前错误处理非常差。如果通过ajax执行Controller方法,并且该方法导致500(或404或任何其他响应),则呈现500.html页面并将其作为AJAX请求的结果返回。显然,javascript不知道如何处理该HTML,网页看起来只是在等待响应。在AJAX调用期间发生错误时,rails是否有一种简单的方法来呈现error.rjs模板? 最佳答案 您可以在Controller的rescue_action或rescue_action_in_public方法中使用respond_

  5. ruby-on-rails - 重定向 Rails 3 中特定 Controller 的记录器输出 - 2

    我们想要一个Controller集合,我们将所有操作和下游方法的记录器输出路由到一个单独的日志文件。这是一个Rails3项目。在Rails2中,我们通过重新定义“logger”方法来做到这一点,但在Rails3中,记录的方式是使用“Rails.logger”。我试着把Rails::logger=Logger.new(File.join(Rails.root,'log',"reports_controller.log"),10,1000000)在Controller的顶部,但只有在操作中专门使用Rails.logger的特定情况才会发送到指定的日志文件,Controller的所有默认日志

  6. ruby - 为什么在重定向时,Ruby 的 STDERR 输出先于 STDOUT 输出? - 2

    在bash中,这给出了预期顺序的输出:ruby-e"puts'one';raise'two'"one-e:1:in`':two(RuntimeError)但是如果我将STDERR重定向到STDOUT,我会在输出之前收到错误,这是我不想要的:ruby-e"puts'one';raise'two'"2>&1|cat-e:1:in`':two(RuntimeError)one我想将输出重定向到一个文本文件(它的行为方式与上面的cat相同)并获得输出和异常,但顺序与查看我的输出时的顺序相同终端。这能实现吗? 最佳答案 发生这种情况是因为行缓

  7. ruby - 为什么 Logger 输出到 STDOUT 不会重定向到文件? - 2

    这个脚本被命名为o.rb:@logger=Logger.new(STDOUT)@logger.info"start_time:#{start_time}"当我使用./o.rb运行它时,控制台上的输出是正确的。但是,当我尝试./o.rb>log.txt2>&1时,日志文件是空的!为什么会这样?我在使用简单的puts函数时遇到了同样的问题。更新这将重现此问题:require'logger'logger=Logger.new(STDOUT)loopdologger.info"Thisisatesthaha"sleep(1)end当我使用./foo.rb运行它时,它会正确写入控制台输出。当我运

  8. ruby-on-rails - Ruby On Rails 自定义路由总是重定向到 Controller 的显示操作 - 2

    我正在尝试创建一条新路线,以便我可以利用RoR的路径变量功能,即new_game_path。就我而言,我想使用load_game_path我已经为适当的Controller创建了一个Action,目前路由如下:resources:gamesdoget'load',on::collectionend每次我使用load_games_path它都使用正确的URI,但似乎重定向到GamesController的显示操作并显示游戏的继承显示View。我检查了rakeroutes,我看到我新创建的路线似乎是所需的路径/games/load(文件路径:/views/games/load.html.e

  9. ruby-on-rails - 使用 CloudFlare SSL 在 Rails 4 上进行 force_ssl 重定向循环 - 2

    当使用force_ssl方法(使用CloudFlare的一键式SSL功能实现的SSL)强制执行ssl时,我的Rails4应用程序出现重定向循环。 最佳答案 当我在CloudFlare中从“灵活”设置切换到“完整”SSL设置时,这种情况就停止了。 关于ruby-on-rails-使用CloudFlareSSL在Rails4上进行force_ssl重定向循环,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com

  10. ruby-on-rails - Rails 还是 Sinatra? PHP程序员入门学习哪个好? - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。我使用PHP的时间太长了,对它感到厌倦了。我也想学习一门新语言。我一直在使用Ruby并且喜欢它。我必须在Rails和Sinatra之间做出选择,那么您会推荐哪一个?Sinatra真的不能用来构建复杂的应用程序,它只能用于简单的应用程序吗?

随机推荐