Hey!
Iv programmed a community like blogging/cms system with a log in page
Its an external login page, but I was wondering how I can make the login link change to the username when there loged in
The link is : Fusion Strike; Live! any help would be greatly appreciated!
Ehm, let me get this straight: so you want the login page name ( file ) to become the same name as the user who's logged in?
So say, user "testuser" is loggedin, you want the login page to be: testuser.php?
No.
When you log into Google, the login link changes to your email address
Id like that but insted of an email address
The user name stored in the database.
ooh you mean that. Well that requires your login script & database structure...
But an example would be (login script with username showing when logged in):
Just wrote it so could be some typos not sure, but that's the basic idea. Hope this helped & is what you meantCode:<?php
session_start();
if($_SESSION['logged'] == true AND !empty($_SESSION['username'])) {
echo "Welcome back, ".$_SESSION['username']; //welcome user w/ username
}else{
if($_POST) {
$check_login = mysql_query("SELECT id FROM accounts WHERE username = '".mysql_real_escape_string($_POST['username'])."' AND password = '".mysql_real_escape_string($_POST['password']."' ");
if(mysql_num_rows($check_login) > 0) { //account found? valid login
$_SESSION['logged'] = true; //set login session, indicating user has logged in
$_SESSION['username'] = $_POST['username']; //save username, store in session
echo "Welcome ".$_SESSION['username']; //welcome username with his username
}
}
}
?>![]()
Last edited by webcodez; 02-16-2010 at 08:27 AM.
the login system i have already Fusion Strike; Live! - Login
makes a session_start
will this work when I put the code in the index page?
or will I need to tell it to include /login.php ?!
Thanks for your help mate!
You don't need to include the login page as sessions can be used at any of your pages as long as you set session_start() at the beginning of the page.
So the only thing you need to do is store the username in a session as done in the script above, and then on another page you can use that session to welcome the user ( if logged in ), and put sesion_start() above each of your pages that require use of these sessions.
Let me know if you got it working
Cheers.
Last edited by webcodez; 02-16-2010 at 08:27 AM.
I changed the code to correspond with my database structure
but it didn't work ):
<?php
session_start();
if($_SESSION['logged'] == true AND !empty($_SESSION['name'])) {
echo "Welcome back, ".$_SESSION['name']; //welcome user w/ username
}else{
if($_POST) {
$check_login = mysql_query("SELECT * FROM users WHERE name='$name' AND pass='$pass'");
if(mysql_num_rows($check_login) > 0) { //account found? valid login
$_SESSION['logged'] = true; //set login session, indicating user has logged in
$_SESSION['name'] = $_POST['name']; //save username, store in session
echo "Welcome ".$_SESSION['name']; //welcome username with his username
}
}
}
?>
Got it working!!!!!!
Thanks for your help!! (:
You're welcome, I'm glad I could help![]()
Last edited by webcodez; 02-16-2010 at 08:27 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks