Jump to content

how to prevent direct access of web page by typing url


phplearner2008

Recommended Posts

You can do a simple (and easily bypassable) attempt by checking to see if $_SERVER['HTTP_REFERER'] is set.  Typically that value is set when a link is followed, but not when it's typed in.  This method is however easily bypassed by someone who wants to bypass it.

 

A better answer is you can use sessions to track your user, and remember where they are allowed to go.  Then you can tell them "Sorry, you can only access this page from this other page, and my session data says you didn't".

Link to comment
Share on other sites

Are you familiar with sessions?

 

Assuming you are, let's say you want someone to access page B only from page A.  When they access page A, you store a value in the session like $_SESSION['lastpage'] = 'A'.  Then when they access page B, you can check if $_SESSION['lastpage'] is set to A.

 

If you are concerned about users passing data as arguments to the page, then you should store that data on the server instead.

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.