/    Sign up×
Community /Pin to ProfileBookmark

Notices with user login

I have a user log in which shows a users ID once logged in. The code works really well. However on both the header.php and the login.php I get a notice:

Notice: Undefined index: id in D:wampwampwwwstuffuserlogin2header.php on line 6

Both are the same, undefined index: id.

This is coming from my session ID but I’m not sure how to set the session ID before logging in without effecting my log out.

header.php:

[code=php]
<?php

session_start();
include(“connection.php”);

if ($_SESSION[‘id’] != “”) {
echo “Welcome, “.$_SESSION[‘id’];
echo “<br><form action=’logout.php’ method=’post’><input name=’Logout’ type=’Submit’ value=’Logout’ /></form>”;
}
else{
// show login box

?>
<html>
<head>
<title>Home Page</title>
<head>
<body>
Welcome to the website.<br />
Please log in.<br /><br />
<form name=”frmLogin” action=”login.php” method=”post”>
Username :<br>
<input name=”txtid” type=”text” />
<br/>
Password :<br>
<input name=”txtpwd” type=”password” /><br>

<input type=”submit” value=”Login” name=”btnlogin” />
</form>
</body>
</html>

<?php
}
?>[/code]

Login.php:

[code=php]
<?php
session_start();
include(“validate.php”);
include(“connection.php”);

if ($_SESSION[‘id’] != ” or validatelogin($_POST[‘txtid’],$_POST[‘txtpwd’]) == true){

echo “<head><meta HTTP-EQUIV=’REFRESH’ content=’0; url=index.php’></head>”;
}
else
{
echo “You have posted incorrect log in data you will automatically be redirected”;
echo “<head><meta HTTP-EQUIV=’REFRESH’ content=’10; url=index.php’></head>”;
}
?>
[/code]

I know the code works, but a notice still means its not well written, any advice would be greatly appriciated.

many thanks

Aravona

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 23.2010 — Probably the simplest solution would be:
[code=php]
if(!empty($_SESSION['id'])) {
[/code]
Copy linkTweet thisAlerts:
@AravonaauthorFeb 24.2010 — Thanks works perfectly and doesn't effect my log out! ?
×

Success!

Help @Aravona 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,
)...