Does the included php page can show any info about the requested page? If no, how can I send any?
I have two pages 1.php and 2.php
2.php (which is the secret page) can not be accessed unless the 1.php send him to it.
On 1.php the user log in. So if he login then he can see 2.php
In my code I use include
and my idea is to send something like a string and it will be checked in 2.php for matching. 2.php must be blank if you access it directly.
开发者_开发问答How can I do this?
Thank you!
Register e session variable on 1.php then read this variable on 2.php.
EDIT:
On 1.php, start the session at the beginnin of the script with:
session_start();
then, register a session variabile if the login was successfull, example:
$_SESSION["login"]=true;
on 2.php:
<?
session_start();
if($_SESSION["login"])
{
// your code here
}
else
{
echo "Access denied";
}
?>
Its typical task for sessions. I recommend you to use sessions and session variables.
So I do it like this:
<?php
//this is php 1
session_start();
if($_GET['name']=='Steaven' && $_GET['password']=='abcd') {
$_SESSION['login']=true;
// you could use redirect
header('Location:'php2.php');
}
?>
<?php
//this is php 2
session_start();
if(isset($_SESSION['login'])) {
if(!$_SESSION['login']) {
exit();
}
} else exit();
?>
I hope you can use html forms (for method get.) This is simple code with lot of potential dangerous parts. But in its basics it would work.
Use
$ref = $_SERVER['HTTP_REFERER'];
to find the referrer page on page2.php and match it.
精彩评论