Jump to content

Simply php assistance


Rokboy

Recommended Posts

I'm pretty new to php... I need a short script that I can place at the top of my web page that does the following:

 

In theory, a person only be able to access page2.php unless they come directly from page1.php (The message that appear should say you are not authorized to access this page)

 

I do not want to create login of any kind... Can you help?

 

thanx in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/213638-simply-php-assistance/
Share on other sites

You can use the HTTP_REFERER variable but be aware that this can be forged easily.

 

I'd do it this way with a session variable instead....

 

Add this to all pages:

 

session_start();$lastPage = isset($_SESSION['page']) ? $_SESSION['page'] : '';$currentPage = basename($_SERVER['SCRIPT_NAME']);$_SESSION['page'] = $currentPage;if($currentPage == 'page2.php'){   // this is page2, set the $hasAccess variable   $hasAccess = $lastPage == 'page1.php' ? true : false; }

 

 

in page2.php use the $hasAccess variable to check whether or not to display the message

 

 

<!-- include php script as above --><html><body><?php if(!$hasAccess): ?><p>No access!</p><?php else: ?><p>Welcome to page2...</p><?php endif; ?></body></html>

 

wow guys, thanks so much for helping out. This was amazingly quick. i'm gonna try to implement the suggestions. Will keep you posted.

 

Cheers.

'cause it's amazingly easy once you have an understanding of some basic things in PHP  :D

You should mark this topic as solved, that's why I am here :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.