Jump to content

How to check if the form is posted from my server not other place?


mesh2005

Recommended Posts

I wouldn't rely on http_referrer to tell you if the form is being submitted from your own website. Firstly, some browsers can be configured not to send referring information. Some firewalls also do the same. You will therefore be blocking some legitimate users. And second, headers can be faked.

 

If, as im guessing that you're wanting to secure your form input in this way, then dont. You'll need to check all of your form data to make sure its valid.

Link to comment
Share on other sites

I completly agree with GingerRobot, headers can be faked - infact it screwed over phpBB for a while until they patched it. HTTP_REFERER is not a reliable means of protecting your data.

 

This way also is a bit insecure, but it may suit your purposes. Do a session variable to store the data like so:

 

<?php

session_start();

$_SESSION['current_domain'] = $_SERVER['SERVER_NAME'];

?>

 

Then on your data processing page:

 

<?php

session_start();
$myDomain = "noodles.com";

if( $_SESSION['current_domain'] != $myDomain ){
   
    die( "Nice try bub" );

}

?>

 

That way you have the added security of a purely session wide variable which does not cross-domains

Link to comment
Share on other sites

A good practice is to always use mysql_real_escape_string....Something such as this is generally enough.

 

$variable = mysql_real_escape_string($variable);

 

You could also do a few other things such as truncate the string after it reaches a certain length. This can help prevent people from inserting extremely long strings into your input that can cause problems (just because you set a maxlength variable on your form doesn't mean it has to be obeyed.)

 

Something like this works...Where as 'LENGTH' is the number of characters you want the string to be limited to and the rest dropped.

 

$variable = mb_strcut($variable, 0, LENGTH);

 

If your input is always a positive number the best way to prevent any SQL -injection is to do something like:

 

$variable = round(abs(mb_strcut($variable, 0, LENGTH)), DECIMALS);

 

If your input is not always a positive number you can do this and it is just as effective.

 

$variable = round(mb_strcut($variable, 0, LENGTH), DECIMALS);

 

If your input always consists of only letters you can do this to strip anything else out:

 

$variable =  mb_strcut(preg_replace('|[^A-z]|', '', $variable), 0, LENGTH);

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.