私はウェブサイトとそのログインシステムを作っています。ランディングページ、「新しい投稿」ページ、およびログインページがあります。ログインしていなければユーザーは「新しい投稿」ページにアクセスする必要はありませんが、セッションがなくてもアクセスしようとすると、ログインページに/ login /?新しい。 アドレスバーに?newでログインすると、URLが/ login /だけの場合は「New post」ページにリダイレクトされ、着陸に至ります。Php isset()のヘルプが必要です
if($count == 1 && $row['userPass']==$password && isset($_POST["new"])) {
$_SESSION['user'] = $row['userId'];
header('Location:../new');
} else if ($count == 1 && $row['userPass']==$password) {
$_SESSION['user'] = $row['userId'];
header('Location:../');
}
else {
$errMSG = "Incorrect Credentials, Try again...";
}
完全なコードです::ログインしていない場合
<?php
ob_start();
session_start();
require_once 'dbconnect.php';
$error = false;
if(isset($_POST['btn-login'])) {
// prevent sql injections/ clear user invalid inputs
$email = trim($_POST['email']);
$email = strip_tags($email);
$email = htmlspecialchars($email);
$pass = trim($_POST['pass']);
$pass = strip_tags($pass);
$pass = htmlspecialchars($pass);
// prevent sql injections/clear user invalid inputs
if(empty($email)){
$error = true;
$emailError = "Please enter your email address.";
} else if (!filter_var($email,FILTER_VALIDATE_EMAIL)) {
$error = true;
$emailError = "Please enter valid email address.";
}
if(empty($pass)){
$error = true;
$passError = "Please enter your password.";
}
// if there's no error, continue to login
if (!$error) {
$password = hash('sha256', $pass); // password hashing using SHA256
$res=mysql_query("SELECT userId, userName, userPass FROM users WHERE userEmail='$email'");
$row=mysql_fetch_array($res);
$count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row
if($count == 1 && $row['userPass']==$password && isset($_POST["new"])) {
$_SESSION['user'] = $row['userId'];
header('Location:../new');
} else if ($count == 1 && $row['userPass']==$password) {
$_SESSION['user'] = $row['userId'];
header('Location:../');
}
else {
$errMSG = "Incorrect Credentials, Try again...";
}
}
}
?>
:新しい投稿ページがログインページのコードに続いて
new.phpと呼ばれているとしましょうか?私はここのURLについて何も見ません。 – chris85
URLはhttp://world-sports.000webhostapp.com –
です。常に私をリンク先ページにリダイレクトしています –