/    Sign up×
Community /Pin to ProfileBookmark

"Hey, Your are logged in."

Hello

I searched for this but didn’t know how to word it to get a hit.. so here it goes..

After a user logs in to my site from the index page, how do you make the login form turn in to a message that says ” (username) is logged in click here to logout” I am running MySQL and Phip on Apache.

Any help would be great!

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@ronverdonkSep 06.2006 — Assuming that you have saved the username in a session variable (e.g. $_SESSION['username'], you can print something the following at the top of each page.

[code=php]
print '<table><tr><td style="text-align:right;color:black;font-size:11px;">
You are logged in with user name: '.$_SESSION['username'].
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="Logout.php">Logout</a></span></td></tr></table>';
[/code]


Ronald ?
Copy linkTweet thisAlerts:
@BuezaWebDevSep 06.2006 — Hello

I searched for this but didn't know how to word it to get a hit.. so here it goes..

After a user logs in to my site from the index page, how do you make the login form turn in to a message that says " (username) is logged in click here to logout" I am running MySQL and Phip on Apache.

Any help would be great![/QUOTE]


When the authentication is successful, be sure to grab and set the userID and username into the session variables.

From there, as the previous person said, you can simply echo $_SESSION['username'];

Also, don't forget to put session_start(); at the beginning of your page, or else the session variables won't exist.
Copy linkTweet thisAlerts:
@pcthugSep 07.2006 — [code=php]<?php
session_start();

// check if post variables are set, if not show login form

// authenticate post variables, if invalid show login form

// set session variables from provided post variables
$_SESSION['username'] = stripslashes($_POST['username']);

echo "{$_SESSION['username']} is logged in <a href="/index.php?action=logout" title="Logout">click here</a> to logout.n";

?>[/code]
Copy linkTweet thisAlerts:
@LearnGreekTodayauthorSep 07.2006 — Is this a separate script or do I insert it in my index page?
Copy linkTweet thisAlerts:
@BuezaWebDevSep 07.2006 — It's part of your index page.
Copy linkTweet thisAlerts:
@The_Little_GuySep 07.2006 — this may help you get started:

http://code.d-top.org/scripts/login1.php

This only requires one file.
Copy linkTweet thisAlerts:
@BuezaWebDevSep 07.2006 — this may help you get started:

http://code.d-top.org/scripts/login1.php

This only requires one file.[/QUOTE]


Oh man, that's a horrible tutorial. That tutorial doesn't even filter the user input with mysql_escape_string. No hashing of the password either. ?
Copy linkTweet thisAlerts:
@The_Little_GuySep 08.2006 — Oh man, that's a horrible tutorial. That tutorial doesn't even filter the user input with mysql_escape_string. No hashing of the password either. ?[/QUOTE]
Its just a starter login, It needs to have stuff added to it.
Copy linkTweet thisAlerts:
@boeing747fpSep 08.2006 — like previously stated, be sure your session_start(); is there and that you have session variables for "username" (not so sure if "user id" is needed) from your successful login page.... on your index page, where your login form is, do this
[code=php]if(!empty($_SESSION['username'])){
echo "Hello, <strong>{$_SESSION['username']}</strong>!";
}else{
echo "YOUR LOGIN FORM HERE";
}
[/code]
Copy linkTweet thisAlerts:
@LearnGreekTodayauthorSep 26.2006 — I don't know where to input the script? before form, after frorm.. I can post the code from my index page(login page) if need
Copy linkTweet thisAlerts:
@LearnGreekTodayauthorOct 10.2006 — Does anyone have anymore thoughts on this?
Copy linkTweet thisAlerts:
@boeing747fpOct 10.2006 — i just told you what to do^^ read up 2 posts.
Copy linkTweet thisAlerts:
@LearnGreekTodayauthorOct 10.2006 — I tried to the best of my abilities to add the code to my login page but was unable to get it to work. If I post my login form, do you think you could point out how I should add it.....

<td style="padding-left: 4px;"

background="images/index_09.jpg" width="181">

<!-- Login Form Start -->

<form method="post" action="/vSignup/vAuthenticate.php"

name="Sample">

Username:<input name="username"><br>

Password:<br> <input name="password" type="password"><br>

<input value="Login" type="submit"> &nbsp;</form>
×

Success!

Help @LearnGreekToday spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...