fatepower wrote:Yes thats what im searching for, but i see that u are using a header location. In my code, i want to add it into the same code. The session shall be stored when u have added the correct password, and u should only need to add it once. Please take alook at the script above, its easy to userstand.
Cheers and thanks in advance.
Does your...
err_msg(ERROR,NOT_ADMIN_CP_ACCESS);
stdfoot();
Code include a login form perhaps? How are your users going to log in? The reason roscor redirects the page to login.php is because login.php would contain a login form that, upon posting, would check a database (or whatever "floats your boat") to make sure user credentials were entered properly. Then, it would set the session variable 'valid_user' to anything. At that point, you can take advantage of the
$_SERVER['HTTP_REFERER']
variable to send the page back to the page the user intended to browse. Or you can just store the current page as a session variable for the login page to use:
// page_to_protect.php
if (empty($_SESSION['valid_user'])){
$_SESSION['intended _url'] = $_SERVER['PHP_SELF'];
header("location:https://mysite.com/login.php");
exit();
}
// login.php (excerpt)
header("Location: " $_SESSION['intended _url']);
If the user goes back to your initial page, they will be permitted access (not redirected to the login.php page) since the 'valid_user' session variable will not be empty. roscor's code example is pretty much the standard because it's one if statement that just prevents the code below from running unless a user has successfully logged in.
Of course, if you wanna make this harder, you could always do something like this...
<?php
session_start();
require_once ("include/functions.php");
require_once ("include/config.php");
dbconn(true);
standardheader('PHP Editor');
if (empty($_SESSION['valid_user']))
{
err_msg(ERROR,NOT_ADMIN_CP_ACCESS);
stdfoot();
exit;
}
else
{
?>
<html>
<head>
<title></title>
</head>
<body topmargin="2" leftmargin="1" bottommargin="0" bgcolor="#F9F9FF">
<?php
if (isset($_GET['bestand'])) {
$bestand = $_GET['bestand']; }
if (isset($_POST['bestand'])) {
$bestand = $_POST['bestand']; }
//...