Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Join Date
    Apr 2008
    Location
    Derby
    Posts
    4,668
    Tokens
    262

    Latest Awards:

    Default Displaying logged in users username

    Hi

    Developing my PHP knowledge im making a radio panel, like i've said in another post, and ive looked for tutorials but cant find any on how to display a users username..

    What i though it would be (And im a terrible coder so it wont work!, im coding to gain experience)

    PHP Code:
    <?php
     
    session_start
    ();
     
    if(!isset(
    $_SESSION['logged_in']) 
    }
     
    $username $_SESSION['username']; 
    ?>
     
    Hello, <?= $username ?>! Welcome to my website.
    Any help would be greatly appreciated.. Thank you
    +rep if you can help...
    Back for a while

  2. #2
    Join Date
    Sep 2008
    Location
    UK
    Posts
    3,670
    Tokens
    0

    Latest Awards:

    Default

    echo "$_SESSION['username']";
    Back for a while.

  3. #3
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Quote Originally Posted by Excellent2 View Post
    echo "$_SESSION['username']";
    You don't need quotes around it..

    PHP Code:
    Hello, <?php echo $_SESSION['username']; ?>! Welcome to our website.

  4. #4
    Join Date
    Apr 2008
    Location
    Derby
    Posts
    4,668
    Tokens
    262

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    You don't need quotes around it..

    PHP Code:
    Hello, <?php echo $_SESSION['username']; ?>! Welcome to our website.
    Thank you lots !

    Now, if i where to put that in a seperate file and then added <? include(loggedin.php)?> it would work wouldnt it??

    Sorry im still learning ^^
    Back for a while

  5. #5
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Yes it would. Please quit using short-tags though (<?) and use (<?php).

    PHP Code:
    <?php include "loggedin.php"?>

  6. #6
    Join Date
    Sep 2008
    Location
    UK
    Posts
    3,670
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    You don't need quotes around it..
    I prefer to
    Back for a while.

  7. #7
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Why? It's pointless and stupid.

  8. #8
    Join Date
    Sep 2008
    Location
    UK
    Posts
    3,670
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    Why? It's pointless and stupid.
    Because I prefer to.
    Back for a while.

  9. #9
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Quote Originally Posted by Excellent2 View Post
    Because I prefer to.
    Well, your preference is pointless.

    You're basically telling PHP that you're going to output a string "", but you're actually outputting a variable inside that string, so you're making your program inefficient because it is having to check that string "" for variables ($_SESSION), so you're just putting more work on your program.

    Compared to

    Simple telling PHP you are going to output a variable, you save the time and hassle of having it look through the string for it.

  10. #10

    Default

    I agree with Dentafrice about the fact that it is rather pointless but it should be noted that the added extra execution time is so negligible it shouldn't matter. But still it's a bad habit and should be avoided.

Page 1 of 2 12 LastLast

Posting Permissions

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