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!
Change Login Link, When Logged In
Started by Bioshox, Feb 13 2010 09:31 AM
8 replies to this topic
#1
Posted 13 February 2010 - 09:31 AM
|
|
|
#2
Posted 13 February 2010 - 10:46 AM
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?
So say, user "testuser" is loggedin, you want the login page to be: testuser.php?
#3
Posted 13 February 2010 - 11:13 AM
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.
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.
#4
Posted 13 February 2010 - 12:13 PM
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 meant ;)
But an example would be (login script with username showing when logged in):
<?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
}
}
}
?>
Just wrote it so could be some typos not sure, but that's the basic idea. Hope this helped & is what you meant ;)
Edited by webcodez, 16 February 2010 - 08:27 AM.
#5
Posted 13 February 2010 - 12:29 PM
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!
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!
#6
Posted 14 February 2010 - 01:28 AM
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.
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.
Edited by webcodez, 16 February 2010 - 08:27 AM.
#7
Posted 14 February 2010 - 09:12 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
}
}
}
?>
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
}
}
}
?>
#8
Posted 14 February 2010 - 10:58 AM
#9
Posted 14 February 2010 - 11:01 AM
You're welcome, I'm glad I could help :)
Edited by webcodez, 16 February 2010 - 08:27 AM.


Sign In
Create Account


Back to top









