473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Working with Sessions in Multi Tab Browsers - PHP

Default Working with Sessions in Multi Tab Browsers - PHP
Hi,

I am working on the php project and been stuck on Managing Session in Multiple tabs.

My Problem is ---

When i open a page in firefox window i store the id of product in session[productid] and then manage all stuff related to that product with that session i.e. edit, delete, add subproduct, comment etc..

But when i open another tab in same window for some other product then my previous session for the product 'session[productid]' is overwritten with this new product id. So all the stuffs that i do on the previous product is actually done on new product that i opened in new tab. this is because my session for product id is overwritten.

This is a very serious issue as this might cause to lose of data or data corruption.

Any Help will be greatly appreciated.

Thanks,
Salman
Reply With Quote
Mar 28 '08 #1
5 3073
ronverdonk
4,258 Expert 4TB
...... But when i open another tab in same window for some other product then my previous session for the product 'session[productid]' is overwritten with this new product id ......
Welcome to The Scripts!

When you write something in the $_SESSION['productid'] it stays there until you either unsert the variable, close the browser sesion or overwrite the variable, what else do you expect? You obviously overwrite it, as your posts says.

Now, when you want to keep all these productid's in the $_SESSION array, you can make a sub-array of productid, so the first to come in is stored in
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['productid'][0]
and the second one in
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['productid'][1]
and so on.

Ronald
Mar 28 '08 #2
aktar
105 100+
An alternative you may consider is cookies. But as is with most browsers, cookies must be enabled for this to work.
Mar 28 '08 #3
Thanks for the quick reply. I really appreciate the response to my problem. Thanks buddy...[php]ob_start();
if(version_compare(phpversion(),'4.3.0')>=0) {
if(!ereg('^SESS[0-9]+$',$_REQUEST['SESSION_NAME'])) {
$_REQUEST['SESSION_NAME']='SESS'.uniqid("");
}
output_add_rewrite_var('SESSION_NAME',$_REQUEST['SESSION_NAME']);
session_name($_REQUEST['SESSION_NAME']);
session_start();
$SESS_VAR = "&".session_name().'='.session_id().'&SESSION_NAME ='.session_name();
}
[/php]
I have tried the above code to regenerate session name for each new tab but what happens is it actually regenerate the session name each time i refresh the page in same tab or go to some other link from the page and due to this my sessions are distroyed.

Please guide me if i have coded something strange in this. I have put this code on the first line of my index.php file.

Thanks,
Salman
Mar 31 '08 #4
ronverdonk
4,258 Expert 4TB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 31 '08 #5
Sorry for the inconvinience made to you due to my question without the code tags.
Next time I will take care of this things.

Thanks,
Salman
Apr 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Gary W | last post by:
Hello, I have used SESSIONS on mission critical pages on my site, and if sessions are not enabled / supoorted - these pages will fail. When and why would a session fail? They do not store any...
0
by: James | last post by:
I see that variations on this question have appeared before but I'm still completely stumped. I'm developing an application with a fairly robust graphics component for 3D rendering. I've written...
3
by: Tom Cahill | last post by:
The following code will work perfectly on a PC browser, IE or Netscape. However on a Mac browser (IE, Netscape, or Safari) it does not. I have tried it on OSX and OS9. ANy help anyone can offer...
7
by: Jochem Donkers | last post by:
Hi, So far I wrote a few little things in javascript, but I got a small problem with the following code. Apperently, only Apple's Safari is handling the following code correctly. I took it from...
4
by: tshad | last post by:
I have a RegularExpressionValidator that is testing a field to make sure the number is between 0 and 255. It works fine in IE, but doesn't work in Mozilla or Firefox. ...
0
by: assgar | last post by:
Hello First sorry if there is to much code in this example. I am new to working with multi page forms. I have a search form that gets preloaded info from the database. There are 3...
3
by: boien | last post by:
I have a div container that i have created now i just want to make sure that its horizontally centered in any browser and in any resolution, so that when ever its on 800x600 or 1280x1024 its STILL...
6
by: nishac | last post by:
Can anyone suggest me how to make my drop down menu work in IE7 too.Its working in other browsers.On mouse over the submenus should be displayed.Am attaching my css code hereby.Anyone please check...
2
by: anuparvathy | last post by:
hi! I am doing a website in visual studio 2005.in my asp.net page i have got a grid view which takes the data from the database dynamically. In my source code i have set the wrap property...
0
by: bushramemon | last post by:
hello,,now i m working on multi-threaded client server socket program in which there is one server and multiple clients.........these both are just giving acknowledge to each other that server...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.