Jump to content

Change Login Link, When Logged In

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
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!

#2
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
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?

#3
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
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.

#4
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
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):


<?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
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
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!

#6
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
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.

Edited by webcodez, 16 February 2010 - 08:27 AM.


#7
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
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

}

}

}
?>

#8
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Got it working!!!!!!
Thanks for your help!! (:

#9
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
You're welcome, I'm glad I could help :)

Edited by webcodez, 16 February 2010 - 08:27 AM.