저는 PHP를 처음 사용하고 회원 로그인이없는 웹 사이트를 만드려고합니다 (회원 패널 없음). 로그인 한 경우에만 일부 페이지를 볼 수있는 간단한 웹 페이지가 있습니다.PHP/MYSQL _SESSION에 이름을 부여하는 방법
_SESSION에 임시 이름을 지정하는 방법을 알려주시겠습니까?
이
는 로그인 스크립트입니다if (isset($_POST['formsubmitted'])) {
// Initialize a session:
session_start();
$error = array();//this aaray will store all error messages
if (empty($_POST['e-mail'])) {//if the email supplied is empty
$error[] = 'You forgot to enter your Email ';
} else {
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) {
$Email = $_POST['e-mail'];
} else {
$error[] = 'Your EMail Address is invalid ';
}
}
if (empty($_POST['Password'])) {
$error[] = 'Please Enter Your Password ';
} else {
$Password = $_POST['Password'];
}
if (empty($error))//if the array is empty , it means no error found
{
$query_check_credentials = "SELECT * FROM members WHERE (Email='$Email' AND password='$Password' AND Aprobat='DA') AND Activation IS NULL";
$result_check_credentials = mysqli_query($dbc, $query_check_credentials);
if(!$result_check_credentials){//If the Query Failed
echo 'Query Failed ';
}
if (@mysqli_num_rows($result_check_credentials) == 1)//if Query is successful
{ // A match was made.
$_SESSION = mysqli_fetch_array($result_check_credentials, MYSQLI_ASSOC);//Assign the result of this query to SESSION Global Variable
$_SESSION['start'] = time(); // taking now logged in time
$_SESSION['expire'] = $_SESSION['start'] + (30 * 60) ;
header("Location: about.php");
}else
{
$msg_error= 'Either Your Account is inactive or Email address /Password is Incorrect';
}
} else {
echo '<div class="errormsgbox"> <ol>';
foreach ($error as $key => $values) {
echo ' <li>'.$values.'</li>';
}
echo '</ol></div>';
}
if(isset($msg_error)){
echo '<div class="warning">'.$msg_error.' </div>';
}
/// var_dump($error);
mysqli_close($dbc);
}
이는 로그인 한 사용자가 볼 수있는 페이지의 스크립트입니다.
session_start();
unset($_SESSION["username"]); // where $_SESSION["nome"] is your own variable. if you do not have one use only this as follow **session_unset();**
session_destroy();
header("Location: index.php");
누군가가이 스크립트를 개선하는 데 도움한다면 정말 뵙죠 것 :
ob_start();
session_start();
if(!isset($_SESSION['Username'])){
header("Location: login.php");
session_destroy();
}
는 이는 로그 아웃 스크립트입니다. 내가 원하는 또 다른 것은 _SESSION이 올바르게 만료되었는지 여부입니다.
l m trying to use Prepared statement and I don
사용 방법을 알고 있어야합니다.
이
은 준비된 문을 사용하여 코드이며,이 오류를받을 : 치명적인 오류 : 라인에 /home/siteseby/public_html/login.php에서 비 객체() 멤버 함수의 bind_param에 전화 (38)if (isset($_POST['formsubmitted'])) {
// Initialize a session:
session_start();
$error = array();//this aaray will store all error messages
if (empty($_POST['e-mail'])) {//if the email supplied is empty
$error[] = 'You forgot to enter your Email ';
} else {
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) {
$Email = $_POST['e-mail'];
} else {
$error[] = 'Your EMail Address is invalid ';
}
}
if (empty($_POST['Password'])) {
$error[] = 'Please Enter Your Password ';
} else {
$Password = $_POST['Password'];
}
if (empty($error))//if the array is empty , it means no error found
{
$qstmt = "SELECT * FROM users WHERE (Email = ? AND password = ? AND Aprobat='DA') AND Activation IS NULL";
$stmt = $dbc->prepare($qstmt);
$stmt->bind_param($Email, $Password);
$query_check_credentials = $stmt->execute();
$result_check_credentials = $query_check_credentials;
if(!$result_check_credentials){//If the QUery Failed
echo 'Query Failed ';
}
if (@mysqli_num_rows($result_check_credentials) == 1)//if Query is successfull
{ // A match was made.
$_SESSION = mysqli_fetch_array($result_check_credentials, MYSQLI_ASSOC);//Assign the result of this query to SESSION Global Variable
$_SESSION['start'] = time(); // taking now logged in time
$_SESSION['expire'] = $_SESSION['start'] + (2 * 60) ;
$_SESSION['email'] = $Email;
header("Location: about.php");
exit;
}else
{
$msg_error= 'Either Your Account is inactive or Email address /Password is Incorrect';
}
} else {
echo '<div class="errormsgbox"> <ol>';
foreach ($error as $key => $values) {
echo ' <li>'.$values.'</li>';
}
echo '</ol></div>';
}
if(isset($msg_error)){
echo '<div class="warning">'.$msg_error.' </div>';
}
/// var_dump($error);
mysqli_close($dbc);
} // End of the main Submit conditional.
예. –
내가 이해하면 모르겠다. 그것은 바로이 준비 문 : $ query_check_credentials = $ dbh-> prepare ("SELECT * FROM users WHERE (Email =? AND password =?\t $ query_check_credentials-> execute (array ($ Email, $ Password)); $ query_check_credentials = "WHERE (Email ="DA ") 및 활성화는 NULL입니다. '$ Email'AND password = '$ Password'AND Aprobat = 'DA') 활성화 IS NULL " \t $ result_check_credentials = mysqli_query ($ dbc, $ query_check_credentials); –