Login Script problems

  • Blinkster182
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Apr 02, 2004
  • Posts: 59
  • Status: Offline

Post July 27th, 2004, 2:13 pm

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 27th, 2004, 2:13 pm

  • this213
  • Guru
  • Guru
  • User avatar
  • Joined: Mar 01, 2004
  • Posts: 1242
  • Loc: ./
  • Status: Offline

Post July 28th, 2004, 5:15 am

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
http://www.disabo.com
  • Blinkster182
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Apr 02, 2004
  • Posts: 59
  • Status: Offline

Post July 29th, 2004, 3:05 am

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
  • Joined: Mar 01, 2004
  • Posts: 1242
  • Loc: ./
  • Status: Offline

Post July 29th, 2004, 3:11 am

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.
http://www.disabo.com
  • Cafu
  • Student
  • Student
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 97
  • Status: Offline

Post July 29th, 2004, 7:17 am

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 218 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.