php code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gaurav tiwary
Forum Newbie
Posts: 2
Joined: Mon Apr 13, 2009 11:09 am

php code

Post by gaurav tiwary »

I am totally new in php.
I am building a web site that has user id and password necessary for every work.
now the problem if a user give a direct url of addcontent page for which login is necessary
in my case user is getting that page directly
but what i want , first user will get a login page then he will be directed to addcontent page
plz help me out

gaurav
braveryonions
Forum Newbie
Posts: 14
Joined: Wed Feb 11, 2009 3:31 pm

Re: php code

Post by braveryonions »

I'm not sure if I understand exactly what you need, but I think this could do it on your addcontent page.

Code: Select all

<?
 
// Check login
if($_SESSION['valid_login'] != true) {
header('Location: login.php');
die();
}
 
// The rest of the page is here
 
?>
Is that what you are looking for?
gaurav tiwary
Forum Newbie
Posts: 2
Joined: Mon Apr 13, 2009 11:09 am

Re: php code

Post by gaurav tiwary »

first of all thanks for replying
what ever you given is useful for me but how to define valid login_login
plz reply
JTMarlin8
Forum Newbie
Posts: 4
Joined: Mon Apr 13, 2009 1:43 pm

Re: php code

Post by JTMarlin8 »

gaurav tiwary wrote:first of all thanks for replying
what ever you given is useful for me but how to define valid login_login
plz reply

valid_login is the session variable that needs to be set when the user logs in. Your login page should contain something like this:

Code: Select all

 
try  {
        login($username, $password);
        $_SESSION['valid_login'] = $username;
      }
 
The function login checks to see if the username and password are in the db. If not, it throws and exception. Otherwise, it returns true and proceeds to set the session variable 'valid_login' to the $username.

So your addcontent page should check that session variable to see if there's anything there. If not, then the user has not logged in and should be redirected toward the login page.
Post Reply