Jump to content

[SOLVED] login script not setting session


d22552000

Recommended Posts

 

LOGIN CODE:

include('inc/conf.php'); //session started in here

if (isset($_GET['login'])) {

$login = clean($_POST['l']);

mysql_connect(localhost,'root','');

$result=mysql_query("SELECT `ID` FROM `*`.`users` WHERE user='$login' 
AND pass='".md5($_POST['b'])."'") or die(mysql_error());

if(!mysql_num_rows($result)>0) { html('Error','Login Invalid',true); } else {

session_regenerate_id();
$member=mysql_fetch_assoc($result);

$_SESSION['MID']=$member['ID'];

//Write session to disc
session_write_close();
header("location: index.php?LID=".rand());
exit();
}
}

 

INDEX.PHP:

 

<?PHP
include('inc/conf.php');  //session started in here

if (!empty($_SESSION['MID'])) {
header('location: login.php');
exit();
}

html('Members Home','<div align="right"><a href="login.php?logout">Logout</a></div><br/>Welcome, '.$_SESSION['MIN'].'.  Logged In!<br/><br/>Sorry, but we haven\'t made the user control panel yet ',true);

?>

 

INC/CONF.PHP

<?PHP
include('../html/html.php');
include('../../log.php');

$SELF =        $_SERVER['PHP_SELF'];
$HOST =       $_SERVER['HTTP_HOST'];
$RADD =     $_SERVER['REMOTE_ADDR'];
$RHST =     $_SERVER['REMOTE_HOST'];
$RPRT =     $_SERVER['REMOTE_PORT'];
$REFR =    $_SERVER['HTTP_REFERER'];
$REQU =    $_SERVER['REQUEST_TIME'];
$QURY =    $_SERVER['QUERY_STRING'];
$CONN = $_SERVER['HTTP_CONNECTION'];
$USAG = $_SERVER['HTTP_USER_AGENT'];

__log($SELF,$HOST,$RADD,$RHST,$RPRT,$REFR,$REQU,$QURY,$CONN,$USAG);

    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the past
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

session_start();

?>

 

and I get redirected back to the login page whats wrong?

Link to comment
Share on other sites

don't do all that extra session stuff, to register a session say

<?php
session_start(); //At top
//Some stuff to test
$_SESSION['FieldName'] = $value;
//Done
?>

On the login page say a

<?php
foreach($_SESSION as $key => $value){
echo $key.": ".$value."<br />";
}
?>

That above test is good for testing lots of stuff liek get, post, session.  You might have a spelling issue somehwer

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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