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
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>

 

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.