2013-10-06 2 views
0

그래, 여기에 내 문제가 있습니다. 몇 페이지에 간단한 로그인 시스템을 만들었습니다. 그건 모두 작동합니다. 방금 mysql 데이터베이스에 입력을 제출하는 PHP 폼이있는 다른 페이지를 만들었습니다. 그것도 모두 내 사이트의 다른 페이지에서 작동합니다.
어떤 이유로이 양식을 제출할 때 로그인 페이지로 리디렉션되는 이유가 없습니다. 형태의 검색 결과도 양식 아래에 표시되는 파일 search.php에PHP 폼에 오류가있어 로그인 페이지로 리디렉션됩니다.

<form method="post" action="admin_home.php?page=search.php"> 
<p>Search by date range: </p> 
From: <input type="text" id="from" name="from" />To: <input type="text" id="to" name="to" /> 
<BR> 
<p>Search by:</p> 
Name: <input type="text" id="name" name="name" /> 
Phone Number: <input type="text" id="phone" name="phone" /> 
<input name="export" type="submit" value="Search" /> 
</form> 

그건 : 여기에 내가 제출하려고 양식/코드입니다.

<?php 
session_start(); 
require("admin_logincheck.php"); 
if (!(isset($_SESSION['name']) && $_SESSION['name'] != '')) { 

header ("Location: admin_index.php"); 

} 
?> 

.... 다음 어떤 표시 : 는 여기가 admin_home.php 페이지에있는 로그인 코드입니다.

그리고 여기 내 admin_logincheck.php 페이지입니다 :

<?php 
session_start(); 
session_name("MemberLogin"); 


$hostname = ""; 
$username = ""; 
$dbname = ""; 
$password = ""; 

if($_GET['action'] == "login") { 

mysql_connect($hostname, $username, $password) OR DIE ("Unable to connect to database! Please try again later."); 
mysql_select_db($dbname); 


$name = $_POST['user']; 
$q_user = mysql_query("SELECT * FROM users WHERE username='$name'"); 

if(mysql_num_rows($q_user) == 1) { 

$query = mysql_query("SELECT * FROM users WHERE username='$name'"); 
$data = mysql_fetch_array($query); 
if($_POST['pass'] == $data['password']) { 
$_SESSION['name'] = $name; 
header("Location: admin_home.php"); // This is the page that you want to open if the user successfully logs in to your website. 
exit; 
} 
      else { 
       header("Location: admin_index.php?login=failed&cause=".urlencode('Wrong Password')); 
       exit; 
      } 

} 
else { 
    header("Location: admin_index.php?login=failed&cause=".urlencode('Invalid User')); 
exit; 
} 
} 

// if the session is not registered 
//if(session_is_registered("name") == false) { 
if ($_SESSION['name'] == false) { 
header("Location: admin_index.php"); 
} 
?> 
All 

내 다른 페이지는 잘하지만, 어떤 이유로 한 형태/검색 페이지 내 로그인 페이지로 리디렉션 계속있다. 어떤 도움이라도 대단히 감사합니다. 나는 그것이 LOL을 의미있게 만들었 으면 좋겠다.

if (isset($_SESSION['name']) && !empty($_SESSION['name'])) { 
header ("Location: admin_index.php"); 
} 
+0

이 admin_logincheck에 무엇입니까 :이와

if (!(isset($_SESSION['name']) && $_SESSION['name'] != '')) { header ("Location: admin_index.php"); } 

: – wernersbacher

+0

내 게시물을 편집하고 추가합니다. admin_logincheck가 작동합니다.이 페이지를 추가하는 순간입니다. – dkeeper09

+0

스크립트가 admin_index.php로 리디렉션 중입니까? login = failed & cause = WrongPassword? – wernersbacher

답변

0

이 교체

? 로그인이 작동하지 않는 것 같습니다
+0

if (! empty ($ some_var)) ...로 충분하다는 점에 유의하십시오. isset ($ some_var)을 먼저 사용할 필요가 없습니다. 왜냐하면 empty()는 이미 그것을 수행하기 때문에 (그리고 설정되지 않은 변수는 공백으로 간주하기 때문입니다). –

+0

헤이 보스, 그게 작동하지 않았다. 로그인하지 않으면 admin_index.php로 이동합니다. – dkeeper09

관련 문제