Login Script problems

  • Blinkster182
  • Beginner
  • Beginner
  • Blinkster182
  • Posts: 59

Post 3+ Months Ago

When I first started my site I knew that it would be hard. But this is the hardest bit. My person logs on and on all my pages there Username is shown. But the thing is, if they go onto the main page without being logged on they get this error:
Quote:
Warning: Undefined variable: username in c:\program files\apache group\apache\htdocs\frimps\menu.inc

The only way I can think of doing the page without getting that error is if at the start of the page I set the variable Username to nothing but that logs the person out.

[fade]Please help me. Im confused[/fade]
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

do a test to see if your user is logged in and if so set $username accordingly, if not assign $username a name such as "Guest"


$this
  • Blinkster182
  • Beginner
  • Beginner
  • Blinkster182
  • Posts: 59

Post 3+ Months Ago

So I check to see if the other session variable which Ive called $auth is set to TRUE and if it isnt then set the varialbe $username to "guest"? :?:
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Why not pass the user's username to the variable? Then you can do things like say "Hi George!" on the page when a user is logged in.

If $auth = TRUE means a user is logged in, you could also do as you stated.
  • Cafu
  • Student
  • Student
  • Cafu
  • Posts: 97

Post 3+ Months Ago

I do something like this in my header:

Code: [ Select ]
<? if (!empty($SESSION["username"])) {
    echo("<a href='index.php' class='whitelink'>home</a> | ");
    echo("<a href='logout.php' class='whitelink'>log out</a> [ ".$SESSION["username"]." ]");
 }
?>
  1. <? if (!empty($SESSION["username"])) {
  2.     echo("<a href='index.php' class='whitelink'>home</a> | ");
  3.     echo("<a href='logout.php' class='whitelink'>log out</a> [ ".$SESSION["username"]." ]");
  4.  }
  5. ?>


Basically, if username (which i store in the session) isn't empy, I show it and give them the logout option.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 135 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.