Jump to content

[SOLVED] Session Close


phpretard

Recommended Posts

When I change pages it seems that the session is destroyed.

 

Here is the code:

 


<?php

    session_start();	


$link=mysql_connect("secret","secret","secret");
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

$db=mysql_select_db("secret");
if(!$db) {
	die("Unable to select database");
}

if(!get_magic_quotes_gpc()) {
	$login=mysql_real_escape_string($_POST['login']);
}else {
	$login=$_POST['login'];
}


$qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
$result=mysql_query($qry);
	while($row = mysql_fetch_array($result))
	  {
	  $member_id=$row['member_id'];
	  $firstname=$row['firstname'];
	  $lastname=$row['lastname'];
	  }

if($result) {

	if(mysql_num_rows($result)>0) {

		session_regenerate_id();

		$member=mysql_fetch_assoc($result);

		$_SESSION['SESS_MEMBER_ID']=$member_id;
		$_SESSION['SESS_MEMBER_FNAME']=$firstname;
		$_SESSION['SESS_MEMBER_LNAME']=$lastname;


		header("location: member-index.php");


	}else

		header("location: login-failed.php");

	}
}else {
	die("Query failed");
}
?>

 

Can you tell why by this code?

 

The session might not be ending but it seems to...

 

Each time I go to a new page the form shows up again instead of member index.

 

<?
if (!isset($_SESSION['SESS_MEMBER_ID'])){
echo"
<a name='login_top'></a>
<form style='padding-left:10px;' id='loginForm' name='loginForm' method='post' action='#login_top'>
$log_error
<b>Login</b><br>
<input name='login' type='text' id='login' /><br>
<b>Password</b><br>
<input name='password' type='password' id='password' /><br>
<input style='margin-top:5px; height:23px; width:75px; font-size:10px;' type='submit' name='Login' value='Login' />
</form>
";
}

elseif (isset($_SESSION['SESS_MEMBER_ID'])){
include 'Login/member-index.php';
}
?>

 

Can anyone help with this?

 

If the session is not ending what is the best way to pass session variables from page to page?

 

Link to comment
Share on other sites

change

<?php
if (!isset($_SESSION['SESS_MEMBER_ID'])){
echo"
<a name='login_top'></a>
<form style='padding-left:10px;' id='loginForm' name='loginForm' method='post' action='#login_top'>
$log_error
<b>Login</b><br>
<input name='login' type='text' id='login' /><br>
<b>Password</b><br>
<input name='password' type='password' id='password' /><br>
<input style='margin-top:5px; height:23px; width:75px; font-size:10px;' type='submit' name='Login' value='Login' />
</form>
";
}

elseif (isset($_SESSION['SESS_MEMBER_ID'])){
include 'Login/member-index.php';
}
?>

to

<?php
session_start();
if (!isset($_SESSION['SESS_MEMBER_ID'])){
echo"
<a name='login_top'></a>
<form style='padding-left:10px;' id='loginForm' name='loginForm' method='post' action='#login_top'>
$log_error
<b>Login</b><br>
<input name='login' type='text' id='login' /><br>
<b>Password</b><br>
<input name='password' type='password' id='password' /><br>
<input style='margin-top:5px; height:23px; width:75px; font-size:10px;' type='submit' name='Login' value='Login' />
</form>
";
}

elseif (isset($_SESSION['SESS_MEMBER_ID'])){
include 'Login/member-index.php';
}
?>

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.