Clearing/deleting $_SESSION Array?
I have a $_SESSION array in a nested loop that I need to clear for multiple passes and cannot seem to figure out how to this. I have read the manual on unset and such but there seems to be no clear technique that I can ascertain. PHP Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Clearing Array?
How do I clear an array, I mean how do I free up all items in array, so it becomes empty? I have an array which I reuse in a loop, and need to have it emptied when starting. I fill it like this $blah[ _some_var_from_some_db ]="whatever";
Resetting / Clearing Array
I am having difficulties in getting this correct, what I want to do is sort the prices low to high and display them. That works, but as there are 5 products per page it adds all prices from product 1 to product 2, all prices from product 1 and 2 to product 3 etc.. How to tell php that the array needs to be reset / cleared / set to zero when done with product 1 / product 2 ....? I've tried reset ($ar) and unset ($ar) but both won't work $ar = array( $this->_movieValues['1'] => $row['1price'], $this->_movieValues['2'] => $row['2price'], $this->_movieValues['3'] => $row['3price'], $this->_movieValues['4'] => $row['4price'], $this->_movieValues['5'] => $row['5price'], $this->_movieValues['6'] => $row['6price'], $this->_movieValues['7'] => $row['7price'], $this->_movieValues['8'] => $row['8price'], $this->_movieValues['9'] => $row['9price']); asort ($ar); foreach ($ar as $key => &$val){ $this->_movieValues['sorted'] .="$key";
$_SESSION Array
A small problem that has me kinda baffled. This is the situation: I've set up a self-submitting form FORM.PHP. Once the inputs are validated, the info gets put in SESSION variables and the script redirects the user to a review form REVIEW.PHP which displays the info the user has input and allows them to edit or submit. At the top of that page, I have the following code: --- start code --- foreach ($_SESSION as $key=>$submission) { if ( empty($submission) || ($submission == "") || (strlen($submission) == 0) ) { $DISPLAY[$key] = "« BLANK »"; } else { $DISPLAY[$key] = $submission; } } extract($DISPLAY); --- end code --- The form then displays the info now extracted from the $DISPLAY array. By creating a new array $DISPLAY for the $_SESSION variables, the idea is that this page will indicate the optional fields where the user didn't input data with the string, "BLANK", without changing data in the $_SESSION array. At the bottom, there is an edit button which will take a user back to the original form where the form will be repopulated with the $_SESSION data. The problem I'm having is that the blank $_SESSION variables are being overwritten with the "BLANK" string that's only meant to appear in the review form. Not a huge problem, but I can't figure out why it is happening. Any ideas? I've scoured my code. There's nothing that deliberately overwrites info in the $_SESSION array on the review page. All I can figure is it must have something to do with the way FOREACH operates.
Copying A Multidimensional Array To $_SESSION
Specifically, is it possible to copy a multidimensional array into the $_SESSION array - ie a deep clone of all keys and data? I naively assumed that $_SESSION["myArray"'] = $myArray ; would work but it doesn't appear to work. Is there a single function or assignment I can use, or would I need to use a "foreach" at every level?
Limit On The Size Of An Array In $_SESSION?
I have an object in the session-data which contains a search-result list. It might, at various times, contain 16,000 entries or more. I seem to be noticing, however, that when the size of the result-list is more than around 1,000 records ... the object simply does not get saved into the $_SESSION data at all. The PHP memory-limit is 30 megs. I never see any curious output in the Apache logs, and the application does not fail. The trouble is simply that when the search result is large, and the search-results page enters, it finds that there is no search-result object in the session data. For a smaller result set, and /identical/ code, the object is there.
Removing A Single Value From $_SESSION Array.
What I have here is three select boxes one for all the tables in the db, one listing the table columns in that table and a third to collect the table columns selected stored in a session called $_SESSION['collections']. Up to this point all that works beautiful the session stores the selected collections. But heres what I want to be able to do: I want to remove single values from the $_SESSION['collections']. How do I do that? Code:
Deleting An Element In An Array??
Here is the problem: I've got an array with the following elements $array = ("ice","ice","polka","skate","polka"); thats 2 polka, 2 ice and 1 skate Now i want someway of removing just one of the polka's from it.. so that i'd be left with: $array = ("ice","ice","skate","polka"); what i did was a basic search with for loop and break Code: for($x=0;$x<sizeof($array);$x++) { if($array[$x] == "polka") { echo("match ".$x); break; } } alls well n good till now.. now i've got the index value(2 in this case) of the element which needs to be deleted.. but what should be done now?? is there any function which'll let me delete a particular element in an array? Is there any other way to go around this?
Deleting An Array Item
I have a standard array: $foo = array( 0 => 'abc' 1 => 'def' 2 => 'ghi'); and I have a variable, $bar, which equals 'def' ... and I want to check my array to see if the value of $bar exists in the array, and if it does, delete it from the array. if (in_array($bar, $foo)) { // what goes here??? } I've done this before, but for the life of me, I'm drawing a blank now. Help a bruthah out?
Deleting Array Elements
I need to delete a single element from a one dimensional array. something like. somefunctionname $arrayname[$key]; does anyone know what somefunctionname is or how this is done?
Deleting An Element From An Array
is there some handy and short method to delete an element from an array and than shifting the rest of elements one place ahead e.g array(1,2,3,4,5,6) becomes array(1,2,4,5,6)
Deleting Multidimensional Array
if i have a multi dimentional array, eg: $arr[x][y] = ''; and i want to delete the enrite thing, does unset($arr); rowk, or so i have to delet the second arrays, or how do i do it???
Deleting Blank Entries From Array?
The resulting arrays that i get from my select statements always seem to have some blank entries, in addition to the correct ones. It is rather odd, is there any way i can scan through it and delete these blank entries? Here is the print_r of the arrays. PHP Code:
Checking If A Value Is Not In An Array And Deleting Record From Database
I have been trying to figure this one out and have come up against a brick wall although I know it should be relatively simple. I have a form that passes an array to a php script from a multiple select box that is created dynamically. If a user deselects an item then I want to delete the record from the database but am having a big problem with it. The table in the dbase is quite simple with just three fields: id classid formid Basically, the form send through a classid and a formid value and I want to delete any records that have a classid that are not in the form array and have a formid which is passed as a hidden value. I suppose really what I want is to know how to see if a classid is not in the array that is passed.
Deleting A Single Item From The Middle Of An Array?
I have an array that contain objects, I want to be able to test against the id of that object and remove it from the array. In it's simplest for I want to go from this: $people = array('Tom', 'Dick', 'Harriet', 'Brenda', 'Jo'); ...to this... $people = array('Tom', 'Dick', 'Brenda', 'Jo'); The fact that the items in the array are objects should not matter right? Plus I've already written my loops and conditionals to check which item i need to remove. function removeItem ( $item ) { $len = count ( $_SESSION['basket_arr'] ) ; if ( $len == 1 ) { emptyBasket ( ) ; } else { for ( $i = 0 ; $i < $len ; $i++ ) { if ( $item->id == $_SESSION['basket_arr'][$i]->id ) { //$_SESSION['basket_arr'][$i] must go } } }}
Deleting Database Rows From An Array Of Variables
I have a form with a list of checkboxes, which are each filled with a date in the format 27012007, for example. The name of each of the checkboxes is the same as the date. Basically when the user presses the submit button I would like all rows in the database table "users" with the corresponding column "date" to be deleted when the form variables date correspond to those in the "date" rows. I think all the checked dates might also need to be put into an array. Would anyone know how to do this?
Batch File Deleting And Folder Deleting
I have a folder in my web site where I used php to create and copy in files. but now I can't delete them easily. The only way I know how that is possible is through php. I get an error the following ftp error: 550 th: Permission denied I had the chmod() set to 0777 on every file and folder. But I still seem to loss control over the files when I try and do things with them through other means. I think it is because the user I use to access the files via ftp a diffrent user. So I tryed to add a function with chown() for the new files I was posting and uploading. It didn't work on those new files. so it looks like the only thing I can do is use the unlink() function which deletes the files fine. The only problem is now I have something like 100 sub directories all with files in them. I need to figure out a way to batch delete them. I can't find a script that goes through and finds all file contents including all sub directories and unlink those things. I found some that will use a for loop to list out the contents of a folder but it is just files. No sub directories. Any body got any ideas on which functions I should use or know where a script is that I can base mine off of. I am not sure how to approach this since what I tryed with chown and chmod has failed thus far. I currently have no code and am starting from scratch on this batch flushing of my directory.
Clearing Files
How could I clear the contents of a text file? As in leave the file, but make it empty in prepartation of re-writing it.
Clearing Post
Im working on a complicated form and I have a quick question. After you submit data via Post, that data is no longer there. Right?
Clearing Cookies
I have written a shopping cart that works exactly as desired except for two things. The first problem is if the customer reenters the store and starts another order ( before the cookie times out ) it adds the new info to the previous order. My thinking gets mixed when clearing the cookie. How do I clear the cookie on the users machine AND on the server? Can I set the cookie to a set value, such as zero then when reentering look for that condition and if true assign a new cookie? The second problem appears when items are in the shopping cart and the customer leaves the site. It leaves the items in the database pointing to that particular session. Is there a function I can use to clear the table of items relating to that session? Code:
Clearing Up Older Files
Wonder if you bunch can help me (again!)... i'm looking for a way to read the filenames and dates in a directory, and delete everything which is more than 24 hours old. It's gonna be part of a garbage cleaning routine for old temporary downloaded files.
Cache Clearing Problem
when a form is submitted in php to mysql for eg., and when the page is refreshed the same record is inserted again. I need to clear browser cache. I tried using unset() and also header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); Is there something I am missing.
Clearing Out All $_SESSOIN Variables?
In a particular session, I set a bunch of $_SESSION vars. Is there any way of erasing/purging all of them in one fell swoop or must I iterate through each one or even list them out ... $_SESSION["a"] = ""; $_SESSION["b"] = "";
Clearing Checkbox Property
I am currently working on a phonebook system whereby people can add their own names to the database. So I also have an edit facility. Within my form however I have 3 checkboxes. What I need to know is say someone clears their checkbox, how do I get that to clear the table field?? At the moment, if they de-select the field then it adds it doesn't change the field. Also note, i created a separate column for each of the checkbox fields (they are called roles1, roles2, and roles3). I have included my code for how I can tell if the box should be checked or not. Code:
Clearing Out The $_FILES Variable
I posted yesterday and no one answered; I"m wondering if this list is having tech difficulties.... I'm having trouble with my $_FILES variable. What my program does is allow a person to have an image file on their web page. So if there is an upload, it processes it (resizes it if need be). If they choose to keep their old picture, it isn't supposed to do anything, but it still seems to be passing in a $_FILES variable ANYWAY! I did some wrangling to have it process the image based on another field, a checkbox that is checked showing the existing image and it indicates to keep it if it's on ($processsimage="no") But why is it still passing in a value for $_FILES['thefield'] anyway when there isn't anything in that field for upload? It poses a problem when they are adding a page that might not have an image on it (it's a content manager). I hope someone can help with this perplexing problem. I can't go back to using globals as I am on a quest to get away from using globals because it's a security risk, and I've been hacked already, and my ISP would like me to change my evil, global ways and so would i!
Clearing A MySQL Table At A Specified Time
Is there an efficient way to clear a MySQL table at a specified hour every month short of using cron? The idea is that the table needs to be cleared on the first day of every month in the first hour. Writing a script that deletes the contents of a table is a no brainer (in fact, I would hesitate to call it a script). The problem, as it presents itself in PHP, is an efficient method of insuring that the PHP script runs at the right time on the right day.
Clearing Cookies In Netscape When Done Shopping?
Got a real problem with clearing a cookie in netscape once a customer's order is completed (payment processor accepted). I was using setcookie("cart_id", ""); initially to clear the cookie which worked in IE but not in Netscape. I've tried setting an expiry time to it and a host of others. Does anyone have special tricks to getting rid of them? I NEED to have the cookie clear upon the order being accepted and nothing is working in Netscape.
Completely Clearing A Variable's Contents
I have a variable, say $this_ol_vari. In a previous action, I set $this_ol_vari = 1; now I want to "clear" $this_ol_vari so that an ISSET($this_ol_vari) function would return false. I've tried setting it to 0, NULL, "NULL", "0", "", and " ".
Options For Clearing Text Fields?
I am new to php and html. I'm modifying a journal article database application. Text field input (title, authors, journal, etc.) and associated pdf file are uploaded. Successful completion prints a sentence at the top but the text fields are not cleared. Headers have already been sent so I can't use header (right?). I want the text fields empty so the user can enter data for the next pdf to upload. Code:
Clearing A Table's Primary Keys In MySQL
This may be a silly question, but is there a way to clear out primary key's in a table so that the next entry starts over at 1 again? We have a database that we have done a lot of testing in, and now that we want to go live we would like to have all the keys start at 1. Do I have to drop and recreate all the tables or is there a way to do this via a command?
Clearing Shopping Cart From Session (cookie)
I have used the shopping cart thats on the Adobe site (http://www.adobe.com/devnet/dreamweaver/articles/php_cart_5.0.html) It all works fine except now I need to clear the basket once the order has gone through How can this be done? I have used code for another similar site I have done before but it doesnt clear it. I think its using sessions/cookies differently but dont know really The code I used for other site is Code:
Clearing The Input Text Field After Submiting The Form To A New Page
I have a page with a form with an input text field ... and when a user types his/hers ID ... and submits the form - his/hers page opens in a NEW window .... but the value (ID) that was written in the original window remains. I want to make sure that the form input field on the original page becomes "invisible" - by refreshing/reloading the original page or just by clearing the input form after submission. For now I have put in a meta refresh tag in the head of the html file ... but that is not the solution ... becouse I only need a one time refresh/reload of the page ... and this is to happen right after the input text value is being submitted.
$_session
I'm trying to pass a session variable thru a function and have the variable print out futher down the script. The variable should be echoed but it isn't unless the page is refreshed. I found a work around but it doesn't seem right. My script is working with the way the code is, so my question is why do I have to call session_register() after $_SESSION to make the variable print without refreshing and if this is wrong what is the proper way of doing it? PHP Code:
$_SESSION
I'm running PHP4.2.3 on W2K box with Apache 1.3.2 I need to set up a login page and some session control for a site I'm working on. I know that there are numerous ways of doing this. Can anyone tell me the benefits/pitfalls of using $_SESSION. over a class (or any other similar class like session control) called sessMan that stores the session detail in MySQL with all sorts of fancy encrypting code. How secure is $_SESSION?
$_SESSION
I'm having trouble with the final step to writing a support site for a voluntary body - that is, to impose password-controlled access. Office staff start at entry.php which asks for username and password. Once they have been input, the visitor is passed to entry_check.php which interrogates the database. If the username and password are not valid, entry_check.php exits, returning the user to entry.php. Code:
$_session
I use $_SESSION to set/get my session variables in my scripts. However I am unable to get the current session id. I don't know where to find it! PHP Code:
Using $_SESSION
I have included some variables in my code that I want to be passed from page to page, I wrote the code and everything seemed to be working until I tried my pages from my workplace and discovered that the values weren't being passed. I tried lowering the internet security and allowing cookies and it was fixed. How do I write my code so that all ie sessions will allow the values to be retained?
$_SESSION
Our network Administrator applied an update to our web server recently. After this update was applied (Novell update), my phpMyEdit pages stopped responding. Everything else works fine. After doing some debugging, I found that if I placed all of my pages in the same directory, everything worked. My $_SESSION vars will not transfer to other pages unless that page is in the same directory as the session was started in. I hope this is enough of an explaination. I am clueless as to why thus far. I am going to look at the php.ini file today.
$_SESSION
My session works in the page I set it, however I use onClick to go to another page or even a hyperlink and in the new page the session no longer exists, what may be the reasons for this?
$_SESSION $_POST
I've got a basic user register form, action="POST". in my php code (on the same page, i store the $_POST stuff to a $_SESSION if the user screws a field up so they don't have to reenter all their info. But i'm thinking, why should i use $_POST at all if i can just us the $_SESSION array? or maybe even vice versa? or am i doing this all the wrong way?
$_SESSION Issue
I put together a code that checks for 2 post variables then stores them in a multi-dim $_SESSION array, something like this: If ( isset($_POST['value_a'] && isset($_POST['value_b']) ) { $_SESSION['value']['a'] = $_POST['value_a']; $_SESSION['value']['b'] = $_POST['value_b']; } The problem was that $_SESSION['value']['b'] was being overwritten with the value for 'a' so that both $_SESSION['value'] vars ended up being the same (i.e. $_POST['value_b']. I thoroughly tested it to confirm that this was what happening. I solved the problem by changing the $_SESSION vars to $_SESSION['value_a'] and $_SESSION['value_b']. This was PHP 5, the WAMP package -- I know it's not the latest update of PHP 5. My question: is this a bug (perhaps since fixed) or is there a reason this would be expected behavior?
$_SESSION, Session_is_registered
Platform: Win2k Server, Apache 1.3, PHP 4.2.3 I understand that when using $_SESSION variables, using the "session_register()" function should not be done. I have seen no documentation pertaining the the "why" of this, but I am removing the offending statements from my code anyway. Prior to discovering this tidbit, I had been attempting to save some arrrays in individually registered variables. But the arrays were not being saved between pages. I have also attempted to save the array in a $_SESSION variable (e.g. $SESSION['XYZ']=$XYZ, xyz being an array); still no joy (the data seems to be ending up in the $_SESSION variable, but again it is not saved between page requests). "register_globals" is set to "On" in the INI file. So, to the PHP world at large I ask "what am I missing"?
$_SESSION Not Working?
I have two test files called index.php and index2.php. Index.php: <?php session_start(); $_SESSION['sess_var'] = "hello world"; ?> <a href="index2.php">click</a> ------------------------------------------------------------------------------- Index2.php: <?php error_reporting(E_ALL); session_start(); echo $_SESSION['sess_var']; ?> Index2.php does not display anything?!?! Any ideas?? I look at the session cookie and it has been set with the following inside it: sess_var|s:11:"hello world"; When I placed the line: error_reporting(E_ALL); in index2.php I got the following error: Notice: Undefined index: sess_var in c:program filesapache groupapachehtdocsindex2.php on line 5 line 5 is: echo $_SESSION['sess_var'];
Errors With $_SESSION
the website i'm creating will block "guest" users to some sections of the site. when "guest users" go to "download" page it will show an alert window. logged in members have the access to download page. in "login.php", i create a $_SESSION var, each member has their own level, depending on the type of features they want; $_SESSION['mylevel'] = $member_info['level']; the checking of level to show the alert window is this: Code: if (($_SESSION[mylevel']=='')||($_SESSION['mylevel']==Ə')) { ?> <SCRIPT LANGUAGE=JavaScript> var agree=alert('Please login first.'); window.location='http://www.mywebsite.com' </SCRIPT><? } problem is like this; as a guest user, i go to "download" page, the alert window shows up, saying "please login first". (that's ok) when i log in, then go back to "download" page it still shows the alert window. i have to close the browser first then go to "download" page before its accessible.
Session_register Or $_SESSION
I am using PHP 4.3 i have heard that we should use $_SESSION rather than session_register to register a session...is it true? also I should no longer use session_is_registered() or anything alike....i should use isset($_SESSION()) instead.
$_SESSION Vs. $variable
What am I doing wrong? I set the variable co_name on the first page with an <input.... > and session_start() at the top of both pages. Clicking on a link that takes me to the second page: Script on the second page. echo $_SESSION['co_name']; Does not display value of co_name echo "Variable name co_name = ".$co_name; Displays value of co_name One book suggested using echo {$_SESSION['co_name']}; Does not run. Server is Apache2 Triad
$_SESSION Question
I've a file login.php that create a session, register a variable(myVar) and call (include) another file login1.php in the server side. I need to use the registred variable in the second file but $_SESSION["myVar"] is empty. here is a simplified example of my problem, the command echo ($_SESSION["myVar"]) isn't displaying any thing login.php : ======== <?php $myVar="test" session_start(); session_register("myVar"); include("login1.php"); ?> login1.php : ======= <?php session_start(); echo ($_SESSION["myVar"]); ?>
|