restricting access to a particular page

Discussion in 'PHP' started by newbie12345, May 12, 2010.

  1. #1
    hi im trying to restricting access to a particular page but for some reason it non working
    this is my code for the login
    
    <?php
    session_start();
    include ('connect.php');
    
    if (isset($_POST["submit"])){
    
          $user  = $_POST['u_name'];
          $pass  = $_POST['pwd'];
    	  
    if(!$user){
    echo "please enter your username. <br>";
    }
    if(!$pass){
    	echo "please enter your password";
    	header('Refresh: 3; index.php');
    	}
    if ($user && $pass){
    	   $sql= ("SELECT * FROM user_accounts WHERE username = '$user' AND password = '$pass' ");
    	   $res = mysql_query($sql);
    	   $count = mysql_num_rows($res);
    	   
    	  if ($count ==0){
    	     echo "ur user name or password may be incorrect! try again";header('Refresh: 5; index.php');
    		 
    	  } ELSE {
    	  if ($count ==1){
    	   $row = msql_fetch_array($res);
    	   $_SESSION['is_logged_in']=1;
    	   echo "$user have successfully been logged in. ";
    	   header('Refresh: 5; music.php');
    
    	   }
    	  }
    
    }
    
    }
    ?>
    
    PHP:

    and this is my code for the restricted Page.
    
    <?php
    session_start();
    if(!isset($_SESSION['is_logged_in'])) {
        header("location:accessdenied.php");
    } 
    
    ?>
    
    
    PHP:
    could any one help me with that Please
     
    newbie12345, May 12, 2010 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    header("location:accessdenied.php");
    exit; <-- give it a try
     
    gapz101, May 12, 2010 IP
  3. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #3
    You must use exit in the restricted page script as said by gapz
     
    roopajyothi, May 12, 2010 IP
  4. newbie12345

    newbie12345 Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanx alot guys
     
    newbie12345, May 12, 2010 IP