[英]how does $_session work? and have i done something wrong? php
i am new to php and coding in general.我是 php 和一般编码的新手。 i wanted to make a signup/login system.
我想做一个注册/登录系统。 the signup and login function works but when i login i want to stay on index.php and change the context.
注册和登录功能有效,但当我登录时,我想留在 index.php 上并更改上下文。 but for some reason it doesn't work.
但由于某种原因它不起作用。 have i done something wrong?
我做错了什么吗? this is my login code: (gebruikersnaam = username & wachtwoord = password)
这是我的登录代码:(gebruikersnaam = 用户名和 wachtwoord = 密码)
<?php
if(!isset($_SESSION)){
session_start();
}
include "../../db/dbconnect.php";
include "logs.inc.php";
$gebruikersnaam = mysqli_real_escape_string( $db, $_POST['gebruikersnaam'] );
$wachtwoord = mysqli_real_escape_string( $db, $_POST['wachtwoord'] );
$salt = "46elg9hl50h[[erlt".$wachtwoord."tesy45745jytj57sasfq";
if( empty( $gebruikersnaam ) || empty( $wachtwoord ) ){
header( "Location: ../index.php?/Fields=Empty" );
exit();
}
$sql = mysqli_query( $db, "SELECT * FROM organisatie WHERE OrgGebNaam='$gebruikersnaam' OR OrgEmail='$gebruikersnaam'" );
$result = mysqli_num_rows( $sql );
if( $result < 1 || $result > 1){
header( "Location: ../index.php?/Error/result" );
exit();
}
else {
if( $row = mysqli_fetch_assoc( $sql ) ){
$hashCheck = password_verify( $salt, $row['OrgWW']);
if( $hashCheck == false ){
header( "Location: ../index.php?/Error/Password_Incorrect#1");
exit();
}
else if( $hashCheck == true ){
$_SESSION['ID'] = $row['gebruikerID'];
$_SESSION['Geb'] = $row['gebruikersnaam'];
log_ingelogd();
header( "Location: ../index.ad.php?/Welcome.".$gebruikersnaam );
exit();
}
}
else{
header( "Location: ../index.php?Error/Password_Incorrect#2");
exit();
}
}
?>
and this is index.php:这是 index.php:
<?php
include 'header.php';
include '../db/dbconnect.php';
error_reporting(0);
if( !isset( $_SESSION['ID']) && !isset( $_SESSION['Geb'])) {
?>
<section>
<table id="login-table">
<form action="include/login2.inc.php" method="POST">
<tr>
<td colspan=2 style="text-align: center;"> Login Formulier</td>
</tr>
<tr>
<td><div class="table-text">Gebruikersnaam: </div></td>
<td><input type="text" class="login-table-text" name="gebruikersnaam" required title="Vul hier uw gebruikersnaam in." placeholder="Gebruikersnaam"></td>
</tr>
<tr>
<td><div class="table-text">Wachtwoord: </div></td>
<td><input type="password" class="login-table-text" name="wachtwoord" required title="Vul hier uw wachtwoord in." placeholder="Wachtwoord"></td>
</tr>
<tr>
<td colspan=2 style="text-align: center;"><button id="login-btn" name="submit">Inloggen</button></td>
</tr>
</form>
<form action="signup.php" method="POST">
<tr>
<td colspan=2><hr></td>
</tr>
<tr>
<td><div class="table-text">Als u geen account heeft: </div></td>
</tr>
<tr>
<td colspan=2 style="text-align: center;"><button id="signup-btn" name="signup">Maak een account aan ></button></td>
</tr>
</form>
</table>
</section>
<?php
} // ending if statement.
$gebruikersnaam = $_SESSION['Geb'];
$sql = mysqli_query( $db, " SELECT * FROM gebruikers WHERE gebruikersnaam = '$gebruikersnaam'" );
$row = mysqli_fetch_assoc( $sql );
if( $row['IsAdmin'] == 1){
?>
<div class="container">
<div class="box">
<table class="box-information">
<tr class="box-information-titel">
<td>Gebruikers</td>
</tr>
</table>
<p class="box-information-omschrijving">Bekijk hier de gegevens van alle gebruikers, maak gebruikers aan, verwijder gebruikers en bewerk de gegevens van gebruikers.</p>
<div id="box-btn-gebruiker">
<a href="gebruikers.php"><button class="box-btn">Bekijk ></button></a>
</div>
</div>
<div class="box">
<table class="box-information">
<tr class="box-information-titel">
<td>Onderhoud</td>
</tr>
</table>
<p class="box-information-omschrijving">Bekijk hier het onderhouds tabel zodat u onderhoud kan uitvoeren.</p>
<div id="box-btn-onderhoud">
<a href="onderhoud.php"><button class="box-btn">Bekijk ></button></a>
</div>
</div>
<div class="box">
<table class="box-information">
<tr class="box-information-titel">
<td>Organisatie</td>
</tr>
</table>
<p class="box-information-omschrijving">Bekijk hier alle gegevens die een organisatie heeft.</p>
<div id="box-btn-organisatie">
<button class="box-btn">Bekijk ></button>
</div>
</div>
<div class="box">
<table class="box-information">
<tr class="box-information-titel">
<td>Factuur</td>
</tr>
</table>
<p class="box-information-omschrijving">Bekijk hier alle openstaande facturen, maak facturen en factuurregels.</p>
<div id="box-btn-factuur">
<button class="box-btn">Bekijk ></button>
</div>
</div>
</div>
<?php
}
include 'footer.php';
?>
can someone tell me what i did wrong?有人能告诉我我做错了什么吗? edit: (im not sure but...) i think the problem lies here:
编辑:(我不确定但是...)我认为问题出在这里:
$gebruikersnaam = $_SESSION['Geb'];
$sql = mysqli_query( $db, " SELECT * FROM gebruikers WHERE gebruikersnaam = '$gebruikersnaam'" );
$row = mysqli_fetch_assoc( $sql );
if( $row['IsAdmin'] == 1){
edit: this is my header.php:编辑:这是我的 header.php:
<?php
if(!isset($_SESSION)){
session_start();
}
?> ?>
Maybe missing session_start();也许缺少 session_start(); in file index.php
在文件 index.php 中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.