Jump to content


Photo

Logged in as...


  • Please log in to reply
9 replies to this topic

#1 Plazman65

Plazman65
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 03 March 2006 - 04:49 PM

HI all, Im working my way through some light reading PHP and MYsql development and Im trying to do this on my website;

<?php {if ($_SESSION['MM_Username']))
{ echo 'Logged in as' ($_SESSION['MM_Username']).}
else {echo 'you are not logged in.<br/>'; do_html_url('login.php'),'Login'); exit; } } ?>

I hope I didnt butcher it to bad does anyone see what Im doing wrong? I hope this learning curve gets easier it sure is overwhelming when your starting. Thanks, Michelle

#2 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 03 March 2006 - 05:23 PM

You had a few little errors like putting{,},(,) in unecessary places, try:

<?php
if ($_SESSION['MM_Username'])
{
    echo 'Logged in as ' .$_SESSION['MM_Username']
}
else
{
    echo 'you are not logged in.<br/>';
    do_html_url('login.php', 'Login');
    exit;
} 
?>

*Notice the layout and indentations, it makes your code much easier to read

#3 Plazman65

Plazman65
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 03 March 2006 - 10:56 PM

[!--quoteo(post=351379:date=Mar 3 2006, 09:23 AM:name=php_b34st)--][div class=\'quotetop\']QUOTE(php_b34st @ Mar 3 2006, 09:23 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You had a few little errors like putting{,},(,) in unecessary places, try:

<?php
if ($_SESSION['MM_Username'])
{
    echo 'Logged in as ' .$_SESSION['MM_Username']
}
else
{
    echo 'you are not logged in.<br/>';
    do_html_url('login.php', 'Login');
    exit;
} 
?>

*Notice the layout and indentations, it makes your code much easier to read
[/quote]
Your right it sure does, thank you for responding, its still not working though. Im wondering if the first line is my problem.
if ($_SESSION['MM_Username']) -The first line checks to see if theres a value for MM_Username right?
Im having one of those days and want to make sure Thanks, Michelle


#4 TylerL

TylerL
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 March 2006 - 12:01 AM

Yeah it checks if its a value or if its empty.

Also, place: session_start(); at the top of your file, or else you can't use sessions. Try that, if it doesnt work let me know and I have a few other ideas as to what it might be.

#5 Plazman65

Plazman65
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 04 March 2006 - 01:30 AM

[!--quoteo(post=351459:date=Mar 3 2006, 04:01 PM:name=TylerL)--][div class=\'quotetop\']QUOTE(TylerL @ Mar 3 2006, 04:01 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Yeah it checks if its a value or if its empty.

Also, place: session_start(); at the top of your file, or else you can't use sessions. Try that, if it doesnt work let me know and I have a few other ideas as to what it might be.
[/quote]

hmmm so what are those ideas you got? I know that the session variables are working because I have been using-

<?php echo "Welcome ". $_SESSION['MM_Username'] ."!
YOU ARE CURRENTLY LOGGED IN!<br /><br />" ?>;

I just dont like the login here link showing up when someone is already logged in, teach me to be picky haha
Thanks for the help, Michelle

#6 Plazman65

Plazman65
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 04 March 2006 - 05:07 AM


OK I got the first part working, woohooo the ; was missing from one of the lines.

Now the do_html part isnt working, I definately dont know anything about that part, any ideas?

I just dont like the login here link showing up when someone is already logged in, teach me to be picky.

I would like it to do,

Welcome back 'me' you are logged in. Log out here(with that being a log out link)' ( I havent started working on the logout here part, one challenge at a time)

and then when they are logged out it says,

Hey you your not logged in log in here (log in here link)
( Ok maybe not really say that but you get my point)
Thanks for any help you can provide, Michelle

#7 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 05 March 2006 - 12:08 AM

Can you post some code? because with the code i posted it should only show the login link if the user isnt logged in.

#8 Plazman65

Plazman65
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 05 March 2006 - 05:15 AM

[!--quoteo(post=351726:date=Mar 4 2006, 04:08 PM:name=php_b34st)--][div class=\'quotetop\']QUOTE(php_b34st @ Mar 4 2006, 04:08 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Can you post some code? because with the code i posted it should only show the login link if the user isnt logged in.
[/quote]

<?php
if ($_SESSION['MM_Username'])
{
echo 'Logged in as ' .$_SESSION['MM_Username'];
}
else
{
echo 'you are not logged in. Login Here<br/>';
do_html_url('loginpage.php', 'Login');
exit;
} ?>

Thats what I got so far, everything from the
"Login Here<br/>';" isnt working. Thanks for your help, Michelle

#9 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 05 March 2006 - 03:34 PM

If thats the only code you have so far the problem will be because you have not defined the function "do_html_url()" and you will get an error that looks something like "Fatal error: Call to undefined function do_html_url() in your script location on line 9" if you are just starting to learn php I would replace the function with something a bit simplier like a standard hyperlink so your code would look like:

<?php
if ($_SESSION['MM_Username'])
{
    echo 'Logged in as ' .$_SESSION['MM_Username'];
}
else
{
    echo 'you are not logged in. Login Here<br/>'
         .'<a href="login.php">Login</a>';
    exit;
}
?>

Then you can always read up on functions later.

#10 Plazman65

Plazman65
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 05 March 2006 - 04:50 PM

thanks so much Ill try that, I figured it was something to do with the function stuff and no I have gotten to that "chapter" yet. I would be so lost without these forums thats for sure, thanks everybody




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users