Php oturum açma
08.03.2020 - 01:41
Merhaba arkadaşlar, session kullanarak giriş yapıyordum şimdiye kadar ama artık oturum bilgilerini ömür boyu çerezde tutmak istiyorum ne denediysem olmadı neleri nasıl değiştirmeliyim ne eklemeliyim? yardım edin lütfen !
//register.php
<?php
require_once("includes/config.php");
require_once("includes/classes/FormSanitizer.php");
require_once("includes/classes/Constants.php");
require_once("includes/classes/Account.php");
$account = new Account($con);
if(isset($_POST["submitButton"])) {
$firstName = FormSanitizer::sanitizeFormString($_POST["firstName"]);
$lastName = FormSanitizer::sanitizeFormString($_POST["lastName"]);
$username = FormSanitizer::sanitizeFormUsername($_POST["username"]);
$email = FormSanitizer::sanitizeFormEmail($_POST["email"]);
$email2 = FormSanitizer::sanitizeFormEmail($_POST["email2"]);
$password = FormSanitizer::sanitizeFormPassword($_POST["password"]);
$password2 = FormSanitizer::sanitizeFormPassword($_POST["password2"]);
$success = $account->register($firstName, $lastName, $username, $email, $email2, $password, $password2);
if($success) {
$_SESSION["userLoggedIn"] = $username;
header("Location: index.php");
}
}
function getInputValue($name) {
if(isset($_POST[$name])) {
echo $_POST[$name];
}
}
//login.php
<?php
require_once("includes/config.php");
require_once("includes/classes/FormSanitizer.php");
require_once("includes/classes/Constants.php");
require_once("includes/classes/Account.php");
$account = new Account($con);
if(isset($_POST["submitButton"])) {
$username = FormSanitizer::sanitizeFormUsername($_POST["username"]);
$password = FormSanitizer::sanitizeFormPassword($_POST["password"]);
$success = $account->login($username, $password);
if($success) {
$_SESSION["userLoggedIn"] = $username;
header("Location: index.php");
}
}
function getInputValue($name) {
if(isset($_POST[$name])) {
echo $_POST[$name];
}
}
?>
//config.php
<?php
ob_start();
session_start();
//index.php
if(!isset($_SESSION["userLoggedIn"])) {
header("Location: giris.php");
}
$userLoggedIn = $_SESSION["userLoggedIn"];
471
Görüntülenme
0 Beğeni