Jump to content

php if statements with forms


farril

Recommended Posts

hi there. im new to this forum, iv just started trying to learning php and get my head around it.

 

ive got a website, with a simple login script (atm all it does is acknowledge you are logged in and display your username)

 

ive got a login form, but when you login i want that login form to disapear and have another form containing your user control panel.

 

im having real trouble doing this. how do i go about adding this feature?

Link to comment
https://forums.phpfreaks.com/topic/131641-php-if-statements-with-forms/
Share on other sites

Have you started using SESSIONS yet? They are used to store data between pages. So if you store something in a session, it will be available on the next page, etc.

 

Once you have validated their login, you will want to store something in the SESSION. For this example, let's user $_SESSION['user']:

$_SESSION['user'] = $user;

Now, you should redirect them to whatever page you need to. Finally, on that page, the code would look like:

if($_SESSION['user']){
  //Logged In
  //print User Control Panel
}else{
  //Not Logged In
  //print Login Form
}

 

Note: In every script that uses sessions, make sure you put the following function at the very beginning of the script:

session_start();

it'd be something like...

 

<?
if(isset($_SESSION['auth'])){
     //display links, etc. for people who are logged in...
}else{
     //display login form or whatever it is you want people to see who aren't logged in...
}

 

i mean, that's it in it's simplest form assuming you are using $_SESSION variables to keep track of the login process.

 

i have nothing else to work with in the way of any of your code .. but that's the general idea.

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.