vinpkl Posted November 21, 2008 Share Posted November 21, 2008 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 Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 check out session_regenerate_id() http://uk3.php.net/manual/en/function.session-regenerate-id.php Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 21, 2008 Author Share Posted November 21, 2008 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 Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 I don't actually know what you're doing in your code, so I can't tell you how to use it. When you want a new session id, regenerate the session id. Apart from that I can't help you unless you post some code Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 21, 2008 Author Share Posted November 21, 2008 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 Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 I'm still not sure I understand. When someone logs in there session_id gets stored in the database throught he variable $uniqu_id. When they logout you want it deleted or no? Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 21, 2008 Author Share Posted November 21, 2008 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 Quote Link to comment Share on other sites More sharing options...
gevans Posted November 21, 2008 Share Posted November 21, 2008 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? Quote Link to comment Share on other sites More sharing options...
vinpkl Posted November 22, 2008 Author Share Posted November 22, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.