Hello guys,

I have a question here I want a code that if anyone opened index.php directly give him an message

but if he opened index?=test or something like that should works fine as my function work in this file.

How I can do that ?

If you give me an example that will be much appreciated 🙂

    assuming you mean

    index.php?test=foo

    something like:

    if($_GET['test'] !='foo' ){
    
    exit('no direct access to this file');
    }

    index.php is a bad name for a library (not for user access) file. and if you put it outside the web root users can't access it.

      Thanks Dagon, But I want to hide the only opening for the main script and any other page in the same file work fine.

      For example

      example.com/test.php >>> Should give permissions error
      example.com/test.php?test=anything >>>> Should open it fine

      How I can do that ? Again thanks for your reply.

        2CODE;10963772 wrote:

        example.com/test.php >>> Should give permissions error
        example.com/test.php?test=anything >>>> Should open it fine

        much the same thing, you can use a different header if you prefer

        if(empty($_GET['test']) ){
        header("HTTP/1.0 403 Forbidden");
        exit();
        } 
        

          That's worked, Thanks dago appreciate your help 🙂

            Write a Reply...