Closed Thread
Results 1 to 9 of 9

Thread: Change Login Link, When Logged In

  1. #1
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Change Login Link, When Logged In

    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. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Change Login Link, When Logged In

    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?

  4. #3
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Change Login Link, When Logged In

    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.

  5. #4
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Change Login Link, When Logged In

    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):

    Code:
    <?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
    Last edited by webcodez; 02-16-2010 at 08:27 AM.

  6. #5
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Change Login Link, When Logged In

    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!

  7. #6
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Change Login Link, When Logged In

    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.

  8. #7
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Change Login Link, When Logged In

    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

    }

    }

    }
    ?>

  9. #8
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Change Login Link, When Logged In

    Got it working!!!!!!
    Thanks for your help!! (:

  10. #9
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Change Login Link, When Logged In

    You're welcome, I'm glad I could help
    Last edited by webcodez; 02-16-2010 at 08:27 AM.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Link my user registration/login to my blog?
    By wheay in forum Database & Database Programming
    Replies: 2
    Last Post: 04-26-2011, 10:25 AM
  2. Change button and link after click
    By ifeelcash in forum JavaScript and CSS
    Replies: 2
    Last Post: 02-28-2011, 08:05 PM
  3. PHP/HTML Question. How to change frame after login?
    By jeena1 in forum PHP Development
    Replies: 2
    Last Post: 03-09-2009, 08:28 AM
  4. Change a user Login Shell
    By Wanch in forum Linux/Unix General
    Replies: 2
    Last Post: 08-13-2008, 05:31 AM
  5. Change login resolution of Ubuntu
    By TcM in forum Linux Applications
    Replies: 4
    Last Post: 02-22-2008, 08:24 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts