/    Sign up×
Community /Pin to ProfileBookmark

Sessions Not Working :(…

Hi there… Im making this login script (with alot of help from others) and i have come accross a problem. When i login with my details (I am classed as “leader” in the database) it directs me to the explorer page! Any ideas why?

Fet

index.php

[code=php]
<form action=’LoginScript.php’method=’post’>
<fieldset>
<legend>Log In</legend>
<p><label for=”Forename”>Forename:</label>
<input name=”Forename” type=”text” size=”16″ maxlength=”16″ value=”<?php $_POST[‘Forename’]; ?>”>
</p>
<p><label for=”Surname”>Surname:</label>
<input name=”Surname” type=”text” size=”16″ maxlength=”16″ value=”<?php $_POST[‘Surname’]; ?>”>
</p>
<p><label for=”Password”>Password:</label>
<input name=”Password” type=”password” size=”16″ maxlength=”16″ value=”<?php $_POST[‘Password’]; ?>”>
</p>

<p><input type=”submit” name=”submit” value=”Log In”></p>
[/code]

LoginScript.php

[code=php]
<?php

session_start();

require(“DbConnect.php”);

if(isset($_POST[‘submit’]))
{
$Forename = mysql_real_escape_string($_POST[‘Forename’]);
$Surname = mysql_real_escape_string($_POST[‘Surname’]);
$Password = mysql_real_escape_string($_POST[‘Password’]);
$query = “SELECT * FROM `tblExplorerGroup` WHERE `Forename`=’$Forename’ AND `Surname`=’$Surname’ AND `Password`= ‘$Password'”;
$result = mysql_query($query) or die(“ERROR: ” . mysql_error());
if(mysql_num_rows($result) > 0) # we found a match, so set $_SESSION flag:
{
$_SESSION[‘logged’] = TRUE;

$row = mysql_fetch_object($result);
$_SESSION[‘User_Type’] = (strtolower($row->User_Type) == ‘leader’) ? ‘leader’ : ‘explorer’;

if(isset($_SESSION[‘caller’]))
{
header(“Location: ” . $_SESSION[‘caller’]);
exit;
}
else # otherwise go to main page
{
header(“Location: CheckLogin.php”);
exit;
}
}
else # invalid login, so create error message
{
$error = “<p id=’error’>ERROR: Invalid user name and/or password.</p>”;
}
}

?>
[/code]

CheckLogin.php

[code=php]
<?php

if($_SESSION[‘User_Type’] == ‘leader’)
{
header(‘Location: LeaderMain.php’);
}

else
{
header(‘Location: ExplorerMain.php’);
}

?>

[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisOct 31.2006 — This needs to be in each page in order to maintain the session:
[code=php]session_start();[/code]
Copy linkTweet thisAlerts:
@scottyrobauthorOct 31.2006 — Its always the small things i miss out.. Thanks very much ?
Copy linkTweet thisAlerts:
@pcthugNov 01.2006 — ... [B]Split Threads[/B]

Ok guys, continue your Spanish Translations: [url=http://www.webdeveloper.com/forum/showthread.php?t=126777]here[/url].
Copy linkTweet thisAlerts:
@so_is_thisNov 01.2006 — No es problema.

Salud!
×

Success!

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