2016-09-26 8 views
0

ログインして現在のページにアクセスするにはどうすればよいですか?ここでの設定は、ログインしてmain.phpファイルからのコードは次のとおりです:ログインするリダイレクトするPHP

MGconfigが

<?php 

$user = 'root'; 
$pwd = ''; 
$server = 'localhost'; 
$bdschema = 'MG'; 

// mysql(i) form improved 
$connection = mysqli_connect($server,$user, $pwd, $bdschema); 

if (mysqli_connect_error()) { 
    echo "Error to DB ..." .mysqli_error($connection); 
    exit; 
}; 

mysqli_set_charset($connection, "utf8"); 
//print_r($connection); 


?> 
を提出私がログインしたとき、私は常にホーム・ページに着陸、訪問しています何ページこの構造により私はあなたがを持って見

Login.php(ログインファイル)

<?php 

session_start(); 

$error=""; 
$successMessage=""; 

if ($_POST){ 
    if(!isset($_POST["salada"]) || $_POST["salada"]===""){ 
    $error = "PHP: An email is required <br>"; 
} 


//If some field is missing, there's an error 

if(!isset($_POST["arroz"]) || $_POST["arroz"]===""){ 
    $error .= "PHP: A password is required"; 
} 

if ($error !=""){ 
    $error = '<div class="error-login">'.$error.'</div>'; 

    //try to do login 

}else { 

    //connect to DB 
    require("MGconfig.php"); 

    //read parameters (fields) 

    $email = mysqli_real_escape_string($connection, $_POST["salada"]); 
    $pwd = md5(mysqli_real_escape_string($connection, $_POST["arroz"])); 

    //var_dump($email.$pwd); 

    $result = mysqli_query($connection, "select name, id from users where email = '".$email."' and password = '".$pwd."'"); 

    // alerta erro 
    if (mysqli_num_rows($result) !==1){ 
     $error='<div class="error-login">PHP: Invalid email or password</div>'; 
     header("Location:index.php?error=".$error); 

    }else { 

      $nome = mysqli_fetch_row($result); 

      $_SESSION["name"] = $nome[0]; 
      $_SESSION["id"]=$nome[1]; 

      header ("Location: main.php"); 
      } 
      } 


     } 

     ?> 

MAIN.PHPファイル

 <?php 
     session_start(); 
     ?> 

     <?php 

     include "menu.php"; 


     if(isset($_GET["area"])){ 
     $destino = $_GET["area"]; 
     } else { 
     $destino = "index"; 
     } 

     switch($destino){ 

     case "formsubmit":{ 
      include("formsubmit.php"); 
      } break; 
     case "index": { 
      include("inicio.php"); 
     } break;  

     case "videos": { 
      include("videos.php"); 
     } break; 

     case "FAQs": { 
      include("FAQs.php"); 
     } break; 

     case "quemsomos": { 
      include("quemsomos.php"); 
     } break; 

      case "form": { 
      include("form.php"); 
     } break;        

     default: { 
      include("inicio.php"); 
     } break; 

     } 



     ?> 
     </div> 

     <div> 

    <?php 

    include "footer.php"; 

     ?> 
    </div> 
+1

tsはにクエリパラメータを追加する最も簡単な方法「Login」などのログインページを表示し、そのクエリのパラメータをLocationヘッダーに使用します。 – Scott

+0

答えがありがたいですが、動作していません - "Object not Found ..."と書いてあります。 – icenine

+0

あなたのログインリンクを変更した後、 'header(" Location:main.php ");'を ' – Scott

答えて

1

スコットとMounirOnGithub:これは(ログインファイルを)働い

 header ("Location: main.php?area=".$_POST["area"]); 
0

main.phpファイルの

次のようにフォームにプロパティアクションを追加してください:

<form action="your redirect"> 
    <!-- your code here --> 
</form> 
+0

私の現在の

はログインファイルそのものなので、プログラムはこのファイルを読み込みます。ヘッダーの場所(main.php)を持っています...そして、メインはあなたが指定されたエリアでスイッチを見つける場所です...私はそれを得ません – icenine

+0

多分あなたが 'Login'をしたのは 'inicioにリダイレクトされるでしょう。あなたの 'main.p hp'あなたの最後のコメントで言ったように – MounirOnGithub

+0

私はあなたの人の提案に基づいてすべての可能な組み合わせを試してみました...私はまだ404ページを取得...おかげでanyaway、歓声 – icenine

関連する問題