Block direct access to a php file

Hello again :slight_smile:

So…i have a php file (File 1) and a log in page (file 2) for that file. it works fine, i open the log in page (file 2) and using my password and username i am directed to the php file (file 1). But obviously i see the same file (file 1)if i type its url on the adress bar. Can i block that? I mean make it so that the only way to open the file 1 to be to give the username and password at file 2?

thanks :slight_smile:

You will need to make a way for it to know you can only use it when loggedin

You could use session with an if statement session not logged in and session isset then redirect else show this code

That’s how i do it and it seems to work pretty well.

If you run phpinfo() you can find out what variables are set by the login script, this could be username, or even a session value. Then add an if condition to your pages.

Here is some basic information on sessions that might help!

http://www.tizag.com/phpT/phpsessions.php

Sponsor our Newsletter | Privacy Policy | Terms of Service