이 스크립트를 사용하여이 사이트에서 사용자를 로그인하고 로그인을 기반으로 웹 페이지로 리디렉션했습니다. 그것은 위대한 작품이지만 그들이 리디렉션되는 페이지에 사용자 이름을 당기는 데 문제가 있습니다. 아래의 새 세션 스크립트는 보통 간단한 스크립트로 작동하지만이 리디렉션 스크립트에서는 작동하지 않습니다. 누군가 내가 올바른 방향으로 나를 가리킬 수 있다면 PHP에 매우 익숙해 져서 감사 할 것입니다. 이것이 제 첫 시도입니다. 감사합니다 앨런새 세션 로그인 스크립트가 PHP에서 작동하지 않습니다.
리디렉션 스크립트가 작동합니다.
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="trydata"; // Database name
$tbl_name="users"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1){
// Register $myusername, $mypassword and redirect to file"login_success.php"
$_SESSION['username'] = $myusername;
$_SESSION['password'] = $mypassword;
$result = mysql_fetch_array($result); // get the result set from the query
$redirect = trim($result['redirect']); // get the redirect column's value
if ($redirect == '') {
echo "No redirect value was set!";
} else {
header('Location: ' . $redirect);
exit;
}
} else {
echo "Wrong Username or Password";
}
?>
New session script not pulling loin information through.
<?php
session_start(); // start up your PHP session!
if (isset($_SESSION['username'])
{
echo "You are logged in as ".$_SESSION['username'];
echo "<p>";
echo "<a href='logout.php'> Click here to logout<a/>";
}
else
header ("Location: form.php");
?>
을 배우고 조언. 당신이 사용하고있는 것은 몹시 나쁘다. 'stripslashes'는 역 슬래시가 포함되어 있고 마술 따옴표가 활성화되어 있지 않으면 문자열을 중단합니다. (MQ는 더 이상 사용되지 않으며 나쁜 것입니다.) – ThiefMaster
응답 해 주셔서 감사합니다. 아래 조언과 함께 작동하는 것으로 보입니다. PHP에 대한 더 나은 튜토리얼을 얻게 될 것입니다. 다시 고마워. 방패 –