Zend - The PHP Company




Security

Add Code


password protection using PHP javaScript & HTML  

Type: code fragment
Added by: wcmunger
Entered: 18/08/2000
Last modified: 08/12/1999
Rating: ** (8 votes)
Views: 12915
I used a html form that has a password field named password and a submit button named submit. When the submit button is clicked the page reloads with the $password variable sent back to the server. Then when php resends the html to the client it includes the appropriate javascript to redirect them to the correct protected page.


<?php 
if($password){ 
  if(
$password==coach){ 
     
?> 
      <script language="JavaScript"> 
      location="http://www.charlottesoccer.com/coach.php3"; 
      </script> 
     <?php 
  
}elseif ($password==admin){ 
      
?> 
      <script language="JavaScript"> 
      location="http://www.charlottesoccer.com/admin.php3"; 
      </script> 
      <?php 
  
}elseif ($password==member){ 
      
?> 
      <script language="JavaScript"> 
      location="http://www.charlottesoccer.com/member.php3"; 
      </script> 
      <?php 
  
}elseif ($password==guest){ 
      
?> 
      <script language="JavaScript"> 
      location="http://www.charlottesoccer.com/guest.php3"; 
      </script> 
      <?php 
  
}else{ 
      
?> 
      <script language="JavaScript"> 
      location="http://www.charlottesoccer.com/signin.php3"; 
      </script> 
      <?php 
  


?> 

You see that as many passords as you need can be set up. 
If there are a large amount of passwords it would be better to set up a select case statement.


Usage Example




Rate This Script





Search



This Category All Categories