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
php code
Moderator: General Moderators
-
braveryonions
- Forum Newbie
- Posts: 14
- Joined: Wed Feb 11, 2009 3:31 pm
Re: php code
I'm not sure if I understand exactly what you need, but I think this could do it on your addcontent page.
Is that what you are looking for?
Code: Select all
<?
// Check login
if($_SESSION['valid_login'] != true) {
header('Location: login.php');
die();
}
// The rest of the page is here
?>-
gaurav tiwary
- Forum Newbie
- Posts: 2
- Joined: Mon Apr 13, 2009 11:09 am
Re: php code
first of all thanks for replying
what ever you given is useful for me but how to define valid login_login
plz reply
what ever you given is useful for me but how to define valid login_login
plz reply
Re: php code
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;
}
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.