question about direct access to url

Discussion in 'PHP' started by sudhakararaog, Mar 20, 2008.

  1. #1
    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.
     
    sudhakararaog, Mar 20, 2008 IP
  2. djliku

    djliku Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    1 & 2

    <?php
    
    $ip = "127.0.0.1"; # change to your ip
    
    if($_GET['firstname']==""&& $_SERVER['REMOTE_ADDR']!=$ip) {
    	echo "Direct Access To This File is Not Allowed";
    } else {
    	#show page here
    }
    
    ?>
    PHP:
    3 Create a .htaccess file in the root and put

    ErrorDocument 404 /custompage.html

    Change /custompage.html to whatever error page you want.
     
    djliku, Mar 20, 2008 IP
  3. sudhakararaog

    sudhakararaog Member

    Messages:
    73
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    thanks for providing the 404 method. it worked.
     
    sudhakararaog, Mar 20, 2008 IP