php - make an url password protected from direct accessing htaccess -


i new .htaccess . have 2 files named page1.php , page2.php,while page2.php in folder , page1.php has link it.i want make page2.php password protected when wants open page2.php directly hitting url.
should open when wants go page page1.php page.

can me out done?

note:i have added following thing .htaccess . here page password protected in both ways no matter open directly or go page page1.php . want make password protected when directly want go page.

authuserfile c:/wamp/www/htaccess_pwd/main/.htpasswd.txt  authtype basic authname "you need authorized!!" require valid-user  <files "page2.php"> require valid-user </files> 

solution1:

if dealing .php files, think easiest code in php. page1.php:

<?php session_start(); $_session["log"]="ok"; ?> 

page2.php:

<?php session_start(); if(isset($_session["log"])){ ?> //your site <?php }else{ ?> not allowed enter!!! <?php } ?> 

solution2:

include password link on page1.php (will cause errors on browsers)

<a href="user:password@http://yourserver/page2.php">log in</a> 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -