Jump to content

Session not being set


papaface

Recommended Posts

Hello,
My script works on everyones server so far except one person.
The sessions arent being set.
Is there anything I can add to the below code to set the session if $_SESSION["username"] and $_SESSION["password"] arent set?
[code]<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require("../includes/checker.php");
require ('../includes/connect.php') ;
require ('../includes/checklogin.php') ;

if ($logged_in == 1)
{
echo "You are already logged in ".$_SESSION["username"];
echo "<br>" . '<a href="submissions.php">' . "Click here to view pending Link Exchanges" . "</a>";
echo "<br>" . '<a href="approved.php">' . "Click here to view approved(active) Link Exchanges" . "</a>";
echo "<br>" . '<a href="logout.php">' . "Click here to logout!" . "</a>";
exit;
}

if (isset($_POST["submit"]))
{
if(!$_POST["username"] | !$_POST["password"])
{
die("You did not enter the required fields");
}

$check = mysql_query("select username,password from users where username='".$_POST["username"]."'") or die ("error" . mysql_error());
list($username,$password) = mysql_fetch_array($check);

$_POST["username"] = stripslashes($_POST["username"]); //strip the slashes

if (!$_POST["username"] == $username)
{
echo "The username you entered does not exist";
exit;
}

$_POST["password"] = stripslashes($_POST["password"]); //strip the slashes

$encpass = md5($_POST["password"]);


if ($encpass != $password)
{
die("Sorry you entered the wrong password");
}
else
{

$_SESSION["username"] = $_POST["username"];
$_SESSION["password"] = $_POST["password"];

echo "You are now logged in " . $_SESSION["username"];
echo "<br>" . '<a href="submissions.php">' . "Click here to view pending Link Exchanges" . "</a>";
echo "<br>" . '<a href="approved.php">' . "Click here to view approved(active) Link Exchanges" . "</a>";
echo "<br>" . '<a href="logout.php">' . "Click here to logout!" . "</a>";
mysql_close($con);

}

}
else
{
echo '<table width="100%" height="100%" cellpadding="2" cellspacing="2" border="0">
<tr>
<td align="center" valign="middle">
<form action="'. $_SERVER['PHP_SELF'] .'" method="post" enctype="application/x-www-form-urlencoded">
Username: <input name="username" type="text" />

Password: <input name="password" type="password" />
<input name="submit" type="submit" value="Submit" />
</form>
</td>
</tr>
</table>';
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/34475-session-not-being-set/
Share on other sites

I should have included the checklogin.php file:
[code]<?php

require ('connect.php') ;

session_start();

if (!isset($_SESSION["username"]) || !isset($_SESSION["password"]))
{
$logged_in = 0;
return;
}
else
{
$pass = mysql_query("select password from users where username='".$_SESSION['username']."'",$con);
list($password) = mysql_fetch_array($pass);

if(mysql_num_rows($pass) != 1)
{
$logged_in = 0;
unset($_SESSION['username']);
unset($_SESSION['password']);
}

if ($password = $_SESSION["password"])
{
$logged_in = 1;
}
else
{
$logged_in = 0;
unset($_SESSION['username']);
unset($_SESSION['password']);
}

}

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162397
Share on other sites

Ah I have found the error:
was:
[code] $_SESSION["username"] = $_POST["username"];
$_SESSION["password"] = $_POST["password"][/code]
should have been:

[code] $_SESSION["username"] = $_POST["username"];
$_SESSION["password"] = $encpass;[/code]

Thanks for all of your help guys!
Link to comment
https://forums.phpfreaks.com/topic/34475-session-not-being-set/#findComment-162941
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.