Jump to content

Recommended Posts

Hi everyone,

 

I've gotten a login setup on a site and it displays somewhere on every page. What i am trying to do is when someone logins I would like it to be switched to a little control panel showing your name and other things that i am able to setup.

 

I'm just not sure how to switch them, maybe this will help you get an idea of what i mean:

 

if (logged in) {

show control panel

 

} else show login

 

 

 

Must i use javascript for this?

Link to comment
https://forums.phpfreaks.com/topic/245039-replacing-something-when-a-user-logs-in/
Share on other sites

Ok So i have a simple login i'm testing with. Which simple is:

 

<form action='login.php' method='post'>

    <input type="text" name="username" /><br>

        <input type="password" name="password" /><br>

<input type="submit" value="Log in" />

</form>

 

I want this only to show if the user is logged in. If not I want something else shown.

 

Not sure how to do this though. So it'll end up as something like (i think):

 

if(isset($_SESSION['username']))

{

echo "welcome";

} else *display the login form*

 

 

Not sure how to do this though :s

what login script are you using?

 

you need to see what login.php is doing. obviously login.php is evaluating wether the user and pass are valid or not. if they are, how does it respond? does it set a cookie? a session?

 

post the login.php code if you like.

Everything is still very simple. Right now i'm just using this:

 

<?php

 

session_start ();

 

$username = $_POST['username'];

$password = $_POST['password'];

 

if ($username && $password){

 

$connect = mysql_connect("localhost","root","") or die ("Couldn't connect!");

mysql_select_db("phplogin") or die ("Couldn't find the DB");

 

$query = mysql_query ("SELECT username && password FROM users WHERE username='$username'");

 

echo "hello";

 

} else echo "no username";

 

hmm are you storing passwords in plain text?

i suggest you start from a currently available script. if your struggling with this your gonna hit another roadblock pretty soon!

ro scripts login is ok.

http://www.roscripts.com/PHP_login_script-143.html

 

scroll to the bottom and click download for v1.2

 

in the case of this system, to determin what to show to users/non users:

 

<?php if ( $_SESSION['logged_in'] == TRUE ){}else{};?>

 

or admins/users

 

<?php if ( isadmin ( $_SESSION['user_id'] ) ){}else{}; ?>

 

ok..........

 

<?php

   session_start ();

   $username = $_POST['username'];
   $password = $_POST['password'];

   if ($username && $password){
   
      $connect = mysql_connect("localhost","root","") or die ("Couldn't connect!");   
mysql_select_db("phplogin") or die ("Couldn't find the DB");
   
      $query = mysql_query ("SELECT username && password FROM users WHERE username='$username'");
       
      echo "hello";
      
	$_SESSION['logged_in'] = TRUE;
      
   }    else echo "no username"; ?>

 

to check:

 

<?php if ( $_SESSION['logged_in'] == TRUE ){}else{};?>

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.