0

私がやりたいのは、ユーザーがログインしてから数秒後に私のホームページにリダイレクトすることだけです.これが私のコードです

<?php 
    include_once("config.php");
?>

<?php if( !(isset( $_POST['login'] ) ) ) { ?>



<!DOCTYPE html>
<html>
    <head>
        <title>Codecall Tutorials - Secured Login with php5</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
    </head>

    <body>

        <header id="head" >
                <p>Codecall tutorials User Login</p>
            <p><a href="register.php"><span id="register">Register</span></a></p>
        </header>

        <div id="main-wrapper">
            <div id="login-wrapper">
                <form method="post" action="">
                    <ul>
                        <li>
                            <label for="usn">Username : </label>
                            <input type="text" maxlength="30" required autofocus name="username" />
                        </li>

                        <li>
                            <label for="passwd">Password : </label>
                            <input type="password" maxlength="30" required name="password" />
                        </li>
                        <li class="buttons">
                            <input type="submit" name="login" value="Log me in" />
                            <input type="button" name="register" value="Register" onclick="location.href='register.php'" />
                        </li>

                    </ul>
                </form>

            </div>
        </div>

    </body>
</html>

<?php 
} else {
    $usr = new Users;
    $usr->storeFormValues( $_POST );

    if( $usr->userLogin() ) {

        echo "Welcome"; 


    } else {
        echo "Incorrect Username/Password"; 

    }
}
?>

また、ユーザー登録後にユーザーページを作成していただけると大変助かります。登録コードはすべて設定しましたが、これは実装したいものです。何か案は?

4

5 に答える 5

1

このコード スニペット:

header( 'Location: http://www.yoursite.com/new_page.html' );

必要な場合の参照リンクは次のとおりです - http://php.net/manual/en/function.header.php

于 2013-04-11T03:37:45.117 に答える
1

PHPリダイレクトを行う方法は次のとおりです。

 header('location:index.php');
于 2013-04-11T03:37:56.633 に答える
1

追加してみる

header();phpfunction を使用して、ページを必要な特定の場所にリダイレクトします。

if( $usr->userLogin() ) {
        ob_start(); // use output buffering to avoid "header already sent error"
        echo "Welcome"; //should try to remove this if you want because its unecessary now since your redirecting your page
        header('Location: pagetoredirect');
        ob_end_flush(); //now the headers are sent

    } else {
        echo "Incorrect Username/Password"; 

    }

ソース ( PHP.NET )

于 2013-04-11T03:38:01.680 に答える
0

最初にhtmlをクリアする必要があります:

  1. トップ パーツ コードを次のようにします。

    <?php 
        include_once("config.php");
    
        if( !(isset( $_POST['login'] ) ) ) { ?>
    
  2. リダイレクトする場所を追加headerします。

        if( $usr->userLogin() ) {
            header('Location: /path/to/new/page.php');
        } else {
            echo "Incorrect Username/Password"; 
        }
    
  3. 別の方法は、javascript を使用することです。

        if( $usr->userLogin() ) { ?>
    
            <div class="message">
                Thank you for logging in. You will be redirected in few seconds.
                Click <a href="/path/to/new/page.php">here</a> if not redirected.
            </div>
            <script type="text/javascript">
                window.location = "/path/to/new/page.php";
            </script>
        <?php
        } else {
            echo "Incorrect Username/Password"; 
        }
    
于 2013-04-11T03:41:59.337 に答える
0

このように header() を介してページをリダイレクトできます

header("location:yoursite.com?$msg=welcome user");

実際の出力が表示される前に header() を呼び出す必要があることに注意することが重要です...

于 2013-04-11T05:06:21.270 に答える