Jump to content

Recommended Posts

I m new in PHP i m making a new system to learn PHP ..

 

i want to make a login page and every user will use the same page for login. when they will give user id and password and the system will automatically show different page for different user.

 

Sample:

 

Admin will automatically redirect to admin.php page

 

User will automatically redirect to user.php page.

 

Any idea and sample code for it ?? please help me out

 

thanx in advance

<?php
if ($_SESSION[loggedin]=="true"){

header("Location: user.php");}

elseif ($_SESSION[loggedin]=="true"||$usertype=="admin"){
header("Location: admin.php");}?>

 

It should be 'loggedin' and not loggedin unless you have a constant named loggedin.

 

See: http://www.php.net/manual/en/language.types.array.php#language.types.array.foo-bar

I m really sorry to inform u that i m new in this PHP ..

 

I made a database those columns are: id, name, pass & user right

 

when they give the id and pass then the database will compare them and redirect to the desired page.

 

any code for it ?? do i need cookie for it??

  • 1 year later...

Yes, it works! Easy and safe too.

But...

Imagine 2 user:

admin/password

and

Mister/password2

If I log in like (example) admin/password and I will be redirect to admin.php, then I will have free access to the page Mister.php (if I know it)!

How can I do to limit admin to stay in admin pages and Mister to surf only Mister pages?

Thank you...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.