/    Sign up×
Community /Pin to ProfileBookmark

PHP Sessions not Working

I have two pages: index.php and adminHome.php
——————————————————

the code of index.php is

[code=php]
if ($name==’jagdeep’ and $pass==$password)
{
//creating ‘login’ session here
$_SESSION[‘login’] = true;
header(“Location:adminHome.php”);
die;
}
else
{
header(“Location:index.php?msg=Wrong Username or password”);
}
}

[/code]

——————————————————–
and the adminHome.php is

[code=php]
if(isset($_SESSION[‘login’]))
{
echo “Stay Here”;
}
else
{
echo “header(“Location:login.php”);
}
[/code]

but this session is not working

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmNov 17.2016 — Where is the session_start() in each script? At the very top I hope
Copy linkTweet thisAlerts:
@NogDogNov 17.2016 — Assuming you do have a functioning session_start() somewhere before that, it [i]might[/i] help to do a session_write_close():
[code=php]
if ($name=='jagdeep' and $pass==$password)
{
//creating 'login' session here
$_SESSION['login'] = true;
session_write_close();
header("Location:adminHome.php");
die;
}
[/code]
×

Success!

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