Home / admin / Prevent direct file access to functions.php
  • How to Prevent direct file access to functions.php

    prevent-direct-file-access-to-functions-php

    Adding this snippet to the functions.php of your wordpress theme will prevent direct file access to the functions.php file via the URL “http://wpsnipp.com/wp-content/themes/themename/functions.php” Great snippet from Pete over at swisswp.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    if (!empty($_SERVER['SCRIPT_FILENAME']) && 'functions.php' == basename($_SERVER['SCRIPT_FILENAME']))
    {
    die ('No access!');
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

  • Chad

    This throws an error. The  “&&” should actually be “&&” for it to work.

    • Chad

      Oops. That didn’t work. The first && should be the HTML symbol for the ampersand- & amp; (without the space).

  • i try it for my website, but it dont work and the website are down, it work after i change this line :
    die (‘He’s dead, Jim!’);
    todie (‘Hes dead, Jim!’);
    pls correct your code
    THANKS

    • Opps sorry about that I fixed the error. Cheers Enjoey the snippet.

  • Muhammad Nur’Ihsan Berahim Sam

    i suggest this:

    defined( ‘ABSPATH’ ) or die(‘i love you hacker.’);

    you can find ABSPATH in wp-config.php
    if the user load the wp environment correctly, ASBPATH should be defined or we kick them.

  • Muhammad Nur’Ihsan Berahim Sam

    i suggest:

    defined(‘ABSPATH’) or die(‘nothing here.’);

    you can find ABSPATH in wp-config.php

  • saeed

    it’s ok but how can we use it?