Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Prevent direct access to PHP Form's Action Page
Old 04-05-2011, 04:17 AM Prevent direct access to PHP Form's Action Page
Novice Talker

Posts: 11
Trades: 0
Hello,

I have a PHP Form script which submits form data to the action page (resultd.php)

Is there anyway to disable people from directly access results.php
results.php has the necessary code which check for submit variable etc.

My very specific question: is there any way I can allow results.php to only to be access from 127.0.0.1 and no one else ?
I am on LAMP platform.

Thx
Sans
rsgs is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-05-2011, 05:23 AM Re: Prevent direct access to PHP Form's Action Page
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I'm not 100% sure exactly what you're asking, but here's what I think:

When a form is submitted, the request comes from the user not the server. If you only allow requests from localhost then no one can use the form unless they happen to be on the local machine your server is running on.

I think what you want to do is
1. Only allow POST requests to results.php
2. Prevent POST requests that did not originate from the intended form from being processed.

The first one is simple,
PHP Code:
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
     
//process request

For the second one, try using a nonce. When implemented correctly a user (or spam bot) must actually visit the page the form is on in order to have their request processed. Note that a nonce does not entirely prevent automated requests, but they can make them a little more difficult to pull off.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 04-05-2011 at 05:26 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-05-2011, 05:34 AM Re: Prevent direct access to PHP Form's Action Page
Novice Talker

Posts: 11
Trades: 0
I may have not explained my requirement well.

My form = index.htm
It has <form name="aaa" method="POST" action="result.php">
Everything is working as expected.
I do have a statement like
PHP Code:
if( isset($_POST['Submit']) && ($_POST['Submit'] == "Submit") )
{
....

I just do not want anyone or any BOT to be able to access result.php
I hope I have been able to explain well.

Any ideas ?

Last edited by rsgs; 04-05-2011 at 05:36 AM..
rsgs is offline
Reply With Quote
View Public Profile
 
Old 04-05-2011, 05:39 AM Re: Prevent direct access to PHP Form's Action Page
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
if($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
{


Somehow I don't think that's what you're going for. Why have a public form if you don't want anyone's request to be processed?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-05-2011, 05:43 AM Re: Prevent direct access to PHP Form's Action Page
Novice Talker

Posts: 11
Trades: 0
I happy to have index.htm accessed by everyone.
I do not want bots or spammers etc to access result.php
The file I want to prevent bots from access is result.php
And these bots are not yahoos and google bots, but some random private bots.
rsgs is offline
Reply With Quote
View Public Profile
 
Old 04-05-2011, 10:18 AM Re: Prevent direct access to PHP Form's Action Page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I do not want bots or spammers etc to access result.php
You can't stop bots POSTing the page without stopping EVERYONE accessing the page.

REMOTE_ADDR/REMOTE_IP is the client's address or IP NOT the IP of the hosting server

The ONLY way to stop direct POSTing to the receiving page is to have the form generate a unique ID that has to be present in the POST data for it to be accepted.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-05-2011, 10:53 AM Re: Prevent direct access to PHP Form's Action Page
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by chrishirst View Post
The ONLY way to stop direct POSTing to the receiving page is to have the form generate a unique ID that has to be present in the POST data for it to be accepted.
Just to clarify, a nonce accomplishes this.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-05-2011, 10:58 AM Re: Prevent direct access to PHP Form's Action Page
Novice Talker

Posts: 11
Trades: 0
Can't something be done using .htaccess
On similar lines as some scripts which block direct access of images.
rsgs is offline
Reply With Quote
View Public Profile
 
Old 04-05-2011, 11:00 AM Re: Prevent direct access to PHP Form's Action Page
Novice Talker

Posts: 11
Trades: 0
A quick search yielded this:
http://www.selfseo.com/story-18469.php

Will something like this help ?
rsgs is offline
Reply With Quote
View Public Profile
 
Old 04-05-2011, 11:02 AM Re: Prevent direct access to PHP Form's Action Page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by rsgs View Post
A quick search yielded this:


Will something like this help ?
No.


........
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-05-2011, 11:04 AM Re: Prevent direct access to PHP Form's Action Page
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Just to clarify, a nonce accomplishes this.
Absolutely (and I should have added that fact)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-07-2011, 08:42 PM Re: Prevent direct access to PHP Form's Action Page
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
A good method to use is to generate a random token in the page before the form processing page and save that token in the session and also pass it along with the post form data. Your processing script must see that a session token is set, it exists in the post data, and that it matches the session token before processing can take place.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 04-07-2011, 10:17 PM Re: Prevent direct access to PHP Form's Action Page
Novice Talker

Posts: 11
Trades: 0
I am doing something similar using a form variable.
my idea is to prevent direct access as server level.
Any help using htaccess?
rsgs is offline
Reply With Quote
View Public Profile
 
Old 04-08-2011, 07:57 AM Re: Prevent direct access to PHP Form's Action Page
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
Forget .htaccess: you've been given two simple methods of doing it - use one of them!
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to Prevent direct access to PHP Form's Action Page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38072 seconds with 12 queries