Jump to content

destroy session id on logout and get new id


vinpkl

Recommended Posts

hi all

 

i m using

$unique_id = session_id(); 

 

to get new unique id for my records. Everytime i close the whole browser and open new browser i get a new unique_id.

 

I am not able to destroy the old unique id on logout and get new unique id in my record when i login.

If i have to get a new unique id i have to close all tabs of the browser or say whole browser and open the site again in new browser.

 

I have session_start(); in my config file that is included on all pages.

 

This is my logout script

<? require_once("config.php");
$unique_id = session_id(); 
$qry="delete from cart_table where unique_id='$unique_id'";
mysql_query($qry);
$_SESSION = array(); 
session_unset();
session_destroy();
header("Location:index.php"); 
?>

 

vineet

Link to comment
Share on other sites

hi gevans

 

i looked at your reference. can you tell me how to use it

 

it has

$old_sessionid = session_id();
session_regenerate_id();
$new_sessionid = session_id();

 

do i need to have two separte fields in my database, one for old session and second for new session.

 

actually i m using the session id as unique id in my database. Like i m inserting a order in my database, that order will have 3 products or 3 rows and all 3 products and rows will have same unique id.

In my script if evertime the products or rows inserted are having new unique id then the order id is automatically assumed as new order and the products are added in new order otherwise products get added in old order.

 

$qry="insert into new_order(unique_id,order_date,customer_name) values('$unique_id', curdate(), '$username')";

 

vineet

Link to comment
Share on other sites

hi gevans

 

this is the qry i m using for inserting record

$qry="insert into new_order(unique_id,order_date,customer_name) values('$unique_id', curdate(), '$username')";
mysql_query($qry);

 

in this unique_id is the session id. on logout i want that this unique id that is the session id should be generated everytime new otherwise everyrecord is getting inserted in the record that has old session id.

 

vineet

Link to comment
Share on other sites

yes gevan

 

The unique id or session id is not generated everytime user login in.

 

I m using unique id everywhere like in my cart table and order table and managing the records acording that unique id. At the time customer add to product to cart and then proceed to order the unique id in cart and order will be the same. Its not generated when he logs in but it should be destroyed when logs out.

 

$unique_id=session_id is on everypage. so when user click add to cart buton then also the session id gets inserted into the cart table and so is like with order table when the user goes from cart to order at the time the same unique wil go to order table.

 

i want it to delete it when user logs out.

 

vineet

Link to comment
Share on other sites

How about you force a new id when they login?

 

Straight after login script run this

 

$old_sessionid = session_id();
session_regenerate_id();
$new_sessionid = session_id();

 

Then it will force a new session id, making sure its different from last time?

Link to comment
Share on other sites

hi gevan

 

$old_sessionid = session_id();
session_regenerate_id();
$new_sessionid = session_id();

 

the problem i m facing if i put this in my login script is that when the user add product to cart before login and after that when he logs in then the cart becomes empty.

actually the unique id(session id) gets inserted in the cart table with the product detail when the person clicks add to cart buton whether he is logged in or not.

may be this new sesion id is conflicting.

so this session id should be same at time of add to cart and add to order.

can we put this new regenerate script somewhere else.

 

also this is my login script

if(isset($_REQUEST['submit']))
{
$customer_name=$_REQUEST['customer_name'];
$password=$_REQUEST['password'];
$qry="select * from customer_table where customer_login_id='$customer_name' and customer_choose_pass='$password'";
$result=mysql_query($qry)or die (mysql_error()); 

if(mysql_num_rows($result)==1)
{
$row=mysql_fetch_array($result);
$msg="login successful";
$_SESSION['user_name']=$row['customer_full_name'];
$_SESSION['user_email']=$row['customer_login_id'];

         $old_sessionid = session_id();
session_regenerate_id();
$new_sessionid = session_id();

	}
	else
	{
	$msg="Login ID or password is incorrect";
	}
}
?>

 

this is my logout script

<? require_once("config.php");
$unique_id = session_id(); 
$qry="delete from cart_table where unique_id='$unique_id'";
mysql_query($qry);
$_SESSION = array(); 
session_unset();
session_destroy();
header("Location:index.php"); 
?>

 

vineet

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.