How to Disable Direct Access in Ajax

Ajax lets you asynchronously run submission and processing code. This means that a user submits information without the need to refresh or reload another Web page. To protect against spamming, you can disable direct access, so the code cannot execute from an external source. The code must run from your website, and disabling direct access stops spammers from automating submission.

Instructions

    • 1

      Right-click the Ajax JS file that contains the processing code. Click "Open With" and choose your preferred JS or Ajax editor.

    • 2

      Add the following code to the beginning of the Ajax code to block direct access:

      if (!defined('BASEPATH') exit('Your response here.');

      If the Ajax code is run from any other page but your internal Web pages, the "Your response here" text is displayed. Replace this text with your own.

    • 3

      Save the file and use the Web browser to test the new code. Type the Ajax page in the address bar of the browser. The exit response text displays in the browser.

Related Searches:

References

Comments

Related Ads

Featured