Jump to content

Logged in as...


Plazman65

Recommended Posts

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
Link to comment
Share on other sites

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

[code]<?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;
}
?>[/code]

*Notice the layout and indentations, it makes your code much easier to read
Link to comment
Share on other sites

[!--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) [snapback]351379[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You had a few little errors like putting{,},(,) in unecessary places, try:

[code]<?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;
}
?>[/code]

*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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[!--quoteo(post=351459:date=Mar 3 2006, 04:01 PM:name=TylerL)--][div class=\'quotetop\']QUOTE(TylerL @ Mar 3 2006, 04:01 PM) [snapback]351459[/snapback][/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
Link to comment
Share on other sites


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
Link to comment
Share on other sites

[!--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) [snapback]351726[/snapback][/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
Link to comment
Share on other sites

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:

[code]<?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;
}
?>[/code]

Then you can always read up on functions later.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.