473,661 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unset() unsets more than it should from $_SESSION subarray

17 New Member
hey, i'm basically trying to use php sessions and a bit of javascript to make tabbed browsing within a web page using sessions to store the data of the different opened pages.
Problem: when i unset the first 0 index in the array (ie close the default page) it seems to wipe the other one (can't get it to add more that one anymore) from the array also

the information is held in sub array
[PHP]$_SESSION['pages'][/PHP]
each page has its own array of infomation
[PHP]$_SESSION['pages'][<pageindex>]['title' => value, 'link' => value][/PHP]

the menu down the side uses a foreach loop to echo out each of the pages and links in the ['pages'] array using
[PHP]foreach($_SESSI ON['pages'] as $tid => $page){...}[/PHP]
so that i can get the tab id for the page to unset it from the array
there is a link echoed for each page like so:
[HTML]<a href="menu.php? action=deleteta b&tid='.$tid. '" target="menu">[/HTML]

so that when its clicked, we go to the menu page where we have the following code at the top (the menu page is self contained to do all of this)

[PHP]
switch($_REQUES T['tid']){
case "deletetab" :
unset($_SESSION['pages'][$_REQUEST['tid']]);
break;
<other code for other actions>
Default:
break;
}
[/PHP]

Note: it did use to work correctly when i use a for loop to itterate through the different tabs but then this would have failed because it would after one deletion, have the wrong array id (tid) number for the pages after the one we deleted and also others wouldn't have been displayed that had a higher id number because the for loop used a count($_SESSION['pages']) function to determine how many there were and how high $i should count in the loop, but if we delete from the middle, there are less even though the id's haven't changed....they wern't all displayed! but this new way seems to delete all the data when the default one is clicked, though if you click to delete the second array object, it still leaves the first intact.

Thanks in advance!
Oct 23 '07 #1
2 2028
gm04030276
17 New Member
Anyone? please?! .
Oct 24 '07 #2
niccolo
1 New Member
This answer is about 5 years late. However I came across the same problem and found no help online. So here is the solution in case anyone else ends up here.
Your problem is that when you call unset($_SESSION['pages'][$_REQUEST['tid']]);
PHP will unset everything in $_SESSION['pages'], not just the sub-array.
You need to address it like this:
foreach ($_SESSION['pages'] as $key => $value) {
if ($key == $_REQUEST['tid']) unset($_SESSION['pages'][$key]); }
}
You are unsetting only the $key from within the parent array.
Feb 24 '12 #3

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

Similar topics

1
3798
by: Ante Perkovic | last post by:
Hi, everybody First, the code: --------------------- $maxNo = 500 $numbers = range (1,$maxNo); srand ((double)microtime()*1000000); shuffle ($numbers); $subarray = array_slice ($numbers, 0, 24); ksort ($subarray); // this also don't work!!!
2
2041
by: Xerxes | last post by:
Hi, I have a cart, setup as an associative array (itemid=>qty). When the cart is displayed, the quantity field is an input box and the value can be changed to add/remove an item: echo '<input type = "text" name = "'.$itemid.'" value = "'.$qty.'" size = "3">'; when the "Save changes" button on the page that displays thecart is pressed, a hidden field called "save" is set and the form is submitted.
3
14903
by: Phil Powell | last post by:
PHP: unset($_SESSION); In my original environment (PHP 4.3.2) this line will delete the session variable 'mainDisplay'. But in the testing environment (PHP 4.3.6) the variable persists even after unset() is called. Is there some special setting in PHP that can allow a session to
2
3131
by: Steve | last post by:
I'm working on an e-commerce site, and one of the things I need to do is split an existing order into two orders. The problem I'm having is not creating the new order, but getting the remaining items from the original order cleaned up in the array. What I've tried to do so far is: 1) The data is stored in a serialized array in the order_data field in the orders table. When the order is selected, it is unserialized and called $order_data....
5
2292
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST if ($_POST && (!is_array($leaseObj->errorArray) || @sizeof($leaseObj->errorArray) == 0)) { print_r(array_keys($_POST)); @reset($_POST); $tempPost = $_POST; foreach ($_POST as $key =$val) if (strpos($key, 'new_') === 0) array_remove($tempPost, $tempPost);
1
4505
by: Nico | last post by:
Hi all, I've created the following code: <?php session_start(); ?> <FORM METHOD="POST" ACTION="prova.php"> Add <b>Combination</b><br><br>
5
2317
by: avlee | last post by:
Hello I have application in php where users login and logout. I wanted to create function for administrator which will delete all session's data for other users. For example, each user session data is written in: $_SESSION I wanted to delete such information from administrator account. $session_data = $_SESSION
2
3369
by: O.B. | last post by:
I've written a small operation that sets/unsets bits within an unsigned integer. Is there a better way to do this? static uint setBits(uint original, uint newValue, uint offset, unint mask) { return ((original >offset) & (~mask) | newValue) << offset; } Example:
0
1413
Airslash
by: Airslash | last post by:
Hello, I've written a small function to delete a variable from a class' internal array. The variables on their own are custom class objects, and I'm a bit confused about the whole pass by reference thing. First I'll show you the code: # removes a parameter from the array. # variables are passed as reference to prevent overhead.
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8754
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.