Jump to content

question about direct access to url


sudhakararaog

Recommended Posts

my question is about displaying a friendly message when someone directly types a url in the browser. example i have one file

 

called form.php which processes the information entered in the form and lets say the next page is

thankyou.php?firstname=david by seeing the url if someone types thankyou.php?firstname=smith in the address bar the browser

 

will display smith.

 

1. so if a user enters a url in the browser directly to a specific page("thankyou.php") i would like to display a message

 

like = "Direct access to this file is not allowed"

 

2. with the above method assuming even if i type thankyou.php in the browser directly, though i own the file i will also get

the message "Direct access to this file is not allowed". so i would not like to see this message, i guess for this i need to

 

specify my IP address i suppose.

 

3. also if a user by mistake types the wrong url directly in the address bar ex= www.website.com/abou.php instead of

typing www.website.com/aboutus.php instead of the browser displaying File not found or a 404 error message i would like to

display a customized page which will still have the same look and feel of my website in terms of the layout and i would like

 

to display a message such as = "Page could not be found" Does this have to be done from apache perspective or can it be done

using php. please suggest the procedure in either case apache OR php.

 

please advice.

 

thanks.

 

Link to comment
Share on other sites

If I get this right, you don't want people to be able to directly access restricted pages just by typing the URL into the address bar, right?  In my opinion, the best way to address that issue is to use sessions.  If a user has a valid session and the necessary credentials they will be able to access that page.  If they just type in the URL without first authenticating and invoking a session, then you can use a handler to deny them access to the page. 

 

With regards to your question about having an error page that has the same look 'n' feel as the rest of your site, I know there are definitely ways to do it.  I haven't done anything to that effect myself, but I know that you can use error handlers that allow you to create a standardized error page that fits in with the rest of your site.  You may even be able to make those configurations in your web server platform (in my case, I use Apache). 

Link to comment
Share on other sites

1. so if a user enters a url in the browser directly to a specific page("thankyou.php") i would like to display a message

 

like = "Direct access to this file is not allowed"

define('ACCESS_BLOCKED', true);

if(!defined('ACCESS_BLOCKED')) {
   die ("You can't access this file directly...");

}

 

2. with the above method assuming even if i type thankyou.php in the browser directly, though i own the file i will also get

the message "Direct access to this file is not allowed". so i would not like to see this message, i guess for this i need to

 

specify my IP address i suppose.

well you could do it by IP but ONLY if you have a static IP address. You could use a membership system to check for logged in users and then username but you will need to get a system for that. IP would be easier but ONLY if you have a static one.

 

3. also if a user by mistake types the wrong url directly in the address bar ex= www.website.com/abou.php instead of

typing www.website.com/aboutus.php instead of the browser displaying File not found or a 404 error message i would like to

display a customized page which will still have the same look and feel of my website in terms of the layout and i would like

 

to display a message such as = "Page could not be found" Does this have to be done from apache perspective or can it be done

using php. please suggest the procedure in either case apache OR php.

You need to create 404.shtml in your root directory and then edit that file to display whatever you want...your host probably has a 404 generator script in your hosting panel and if your host uses cPanel then I guarantee you they have a script to generate it those files.

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.