1

アクティブなページのログイン フォームを作成しようとしています。登録も完了。私の問題は、ログインに成功したときに、「header(location:)」でスタートページにリダイレクトできないことです。私を助けてください、またはphpのエラーを修正してください。ありがとう!

注: PHP のリンクはサンプルであり、実際のものではありません。

<?php

$hostname="host"; // Host of MySQL
$user="user"; // Username at MySQL
$password="pass"; // Password at MySQL
$dbname="db"; // Database on MySQL

$connection=mysql_connect($hostname, $user, $password);
    if(! $connection)
        {
            die(''.mysqlerror());
        }
mysql_select_db($dbname, $connection) or die('');

$given_email=mysql_real_escape_string($_POST['email']);
$given_pass=mysql_real_escape_string($_POST['pass']);

$sql="SELECT * FROM users WHERE email='$given_email' and password='$given_pass'";
$result=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_array($result);
$active=$row['active'];
$count=mysql_num_rows($result);

if($count==1)
{    
    //echo "OK";
    header( 'Location: http://www.yoursite.com/new_page.html' ) ;
    //setUrl ("http://testseite.aufderlicht.bplaced.de/loggedin/start.html");
}
    else 
    {
        setUrl ("http://testseite.aufderlicht.bplaced.de/login/err/err.html");
    }

//mysql_close($connection)

?>
4

2 に答える 2

0

PHP ページの代わりに Javascript を使用してリダイレクトを行うことができます。特に、一部の Web ホストでは、ファイルの途中での header() の使用が許可されていないためです。

ここに例があります:

       echo "
         <script type='text/javascript'>
              window.location.replace('http://www.yoursite.com/new_page.html');

         </script>";
于 2013-08-21T01:50:29.280 に答える