Jump to content

Help with Redirect. Weigh in Please!


Trium918

Recommended Posts

Problem: I am trying to prevent the user from accessing

certain pages if they are not logged in. The user will be

redirected to the login page if there is an attempt.

 

The below code is what I have for members.php page

and so far it works. What if the user tries to access the

edit_profile.php directly. There's the problem. I am not

able to get the redirect to work inside of the edit_profile

page.

 

When user enters edit_profile.php in the url it should redirect to login.php

 

 

Edit_Profile.php

 

<?php
function displayLogin(){
   global $logged_in;
   if($logged_in){
      echo "<h1>Logged In!</h1>";
      echo "Welcome <b>$_SESSION[username]</b>, you are logged in. 
     <a href=\"logout.php\">Logout</a>";
   }
else {
      header("Location: login.php"); 
   }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/50164-help-with-redirect-weigh-in-please/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.