Jump to content

how to prevent direct access to php script?


markthien

Recommended Posts

Hi,

i store all my php scripts under /bin folder like process-signup.php. if user directly go to http://www.menggaris.com/bin/process-signup.php, then the script will eventually executed and data will be saved into database. user should go to signup.php first.

how can I prevent this situation from happening?

I am wondering like is there anyway to detect if user directly access process-signup.php instead of accessing from signup.php

 

Thanks & regards,

Mark

Link to comment
Share on other sites

someone said that preferably the php script should put outside the document root.

 

How should I put the process-signup.php outside the document root folder? for example, consider the following code :

<form id="signup_form" action="bin/process-signup.php" method="post">

        <input type="text" name="name" id="name"/>

        <input type="text" name="email" id="email"/>

        <input type="submit" value="submit" name="submit" id="submit"/>

</form>

 

and my document root path is /home/webadministrator/www/root/

and all my php script is under /home/webadministrator/www/root/bin

and now if I put process-signup.php under /home/websiteadmin/www/bin

how should I put the path in the html form?

and I don't think I can put like this?

 

<form id="signup_form" action="/home/websiteadmin/www/bin/process-signup.php" method="post">

 

regards,

Mark

Link to comment
Share on other sites

My Suggestion is avoid sessions/cookies.

 

the PHP_SELF var is a good idea

 

as well as using a constant in yer main pages

so in yer included files, a simple check for the constant can break with an error :)

 

main.php

<?php
define('PAGE','main');
include('includes.php');
?>
Success

 

includes.php

<?php
if(!defined('PAGE'))
{
   die('Illegal Access');
}

// Rest of include
?>

 

Very simple technique :) Nice thing about it, is that u dont need to do a page lookup against PHP_SELF.

 

Good Luck :)

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.