/    Sign up×
Community /Pin to ProfileBookmark

Help with If/else Statement please

In my header, I have a login script as follows:

[CODE]<form action=”login.php” method=”post” name=”logForm” id=”logForm” >
<label>Username: </label><input name=”usr_email” type=”text” class=”required” id=”txtbox” size=”20″>
<label>Password: </label><input name=”pwd” type=”password” class=”required password” id=”txtbox” size=”20″>
<input name=”doLogin” type=”submit” id=”doLogin3″ value=”Login”>
</form>[/CODE]

But if the user is logged in then I want it to say:

<h3>Welcome <?php echo $_SESSION[‘user_name’];?></h3>

So how can I please do the “if user is logged in then say welcome else show login script”?

Thanks,
Adey

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ssystemsApr 14.2012 — [code=php]
<?php if(isset($_SESSION['user_name'])) { ?>
<h3>Welcome <?php echo $_SESSION['user_name'];?></h3>
<?php }else {?>
<form action="login.php" method="post" name="logForm" id="logForm" >
<label>Username: </label><input name="usr_email" type="text" class="required" id="txtbox" size="20">
<label>Password: </label><input name="pwd" type="password" class="required password" id="txtbox" size="20">
<input name="doLogin" type="submit" id="doLogin3" value="Login">
</form>
<?php } ?>
[/code]
×

Success!

Help @djadejones spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...