Session_set_save_handler And Error Handling
Let open, close, read, write, destroy and gc be PHP functions to save
the superglobal array $_SESSION in a database.
I would like to use the following code:
[1] session_set_save_handler(open,close,read,write,gc) ;
[2] session_start();
[3] if(!isset($_SESSION))
[4] {
/* error handling */
exit;
}
/* session okay */
But what will happen, if (e.g.) the database is down?
Means: What kind of error handling can or must be implemented within the
functions open, close, read, write, destroy and gc to get a stable
script? Of course, line [3] is not enough ...
View Complete Forum Thread with Replies
Related Forum Messages:
Error Handling - Simulating A Memory Error
I'm simulating a memory error. I set the limit to 1 Mbyte so when this code is executed an error should appear ini_set("memory_limit","1M"); ... echo("before"); $img = @imagecreatefromjpeg($tsrc); echo("after"); header("location: http://..."); When I run the script the result is the text "before", it seems that the execution is blocked at $img = @imagecreatefromjpeg($tsrc);. Do you have any suggestions? any missing configuration?
View Replies !
Session_set_save_handler
I am using the session_set_save_handler to store session data in m database, but I am having some trouble with getting the session id back out of the database to check if there is a current id running. The following the function I am using to _read the database function _read($id) { global $_sess_db; $id = mysql_real_escape_string($id); $sql = "SELECT data FROM sessions WHERE id = '$id'"; if ($result = mysql_query($sql, $_sess_db)) { if (mysql_num_rows($result)) { $record = mysql_fetch_assoc($result); return $record['data']; } } return ''; } In the code I call the session_set_save_handler from I am able to write to the database fine, but when I try to read from it to see if there is a session in progress I can't seem to get it show me the session id or anything... include 'sessionhandler.inc'; session_start(); $_SESSION['name'] = "mysessionname"; echo " the session data is: ".$record['data']; [test to see if the session is there and that is equal to md5($_SERVER['HTTP_USER_AGENT')] .... Perhaps someone can help. Hope it makes sense what I am trying to do. Thanks.
View Replies !
Php, Mysql, And Session_set_save_handler
Due to the nature of the hosting environment I'm using, I am unable to use sessions the normal way (relying on session files on the host), as it is a load-balanced cluster of servers. As a result, I'm attempting to adapt my application to save session data in a database. I have a "session" class that has all the correct handlers (open, close, read, write, destroy, gc) and the class method have been registered properly. I have verified that session data can be written and read from the database. However, here is the issue I'm encountering. When I go to do something as simple as log in to my application, I can see that the session data is being written correctly (e.g., "username|s:6:ph2007;"), but in practically the same breath, the information is then written over with "username|N;". As a rule, I instruct the script to "reload" the page immediately after handling function input, to prevent actions being repeated detrimentally. I have verified that this causes the "overwrite" of my session data. When I turn off the reload functionality, I am shown the correct screen after logging in, but any other interaction with session data or even manually refreshing the page ends up clearing the session data. Code:
View Replies !
Error Handling - Regular PHP Error
how do i make it so that instead of there being the regular PHP error that PHP will give Warning: blah: blah blah blah it gives something i say like Oops! An error occured. is this possible for every error ever? or do i have to somehow tell it to know if a certain error occured and if so how and if not so. how.
View Replies !
Error Handling
Hi, i'm not sure what the deal is here. Alright, the senario is: i load my classes with error handling set to a custom function, they do their thing, then a template is loaded to display the content. Pretty much a basic setup. But say an extra file loaded and it has a parse error of some sort. No matter what my error_reporting level is whether it be E_ALL or E_PARSE, it won't load my custom function. But of course any notice error will load the function. I've tried loading templates with require, require_once, include, include_once...
View Replies !
Better Error Handling
I cannot pass the of(move_uploaded_file($_FILES["imagefile"]["tmp_name"], $uploaddir . $_FILES["imagefile"]["name"])) statemet and need some more clear errorhandling besides the TRUE FALSE story. Can PHP telll me more in detail why he returns a FALSE?
View Replies !
Error Handling?
Can someone show me an example of or explain how they implemented custom error handling? What are the benifits of doing so? Is it mostly useful for development and debugging? Just trying to understand.
View Replies !
Real Life Examples Of Mysql+session_set_save_handler
In my test setup using my own session handlers with session_set_save_handler and mysql, the session handler opens and close mysql connections. But what if my page also requires some mysql queries? Should I open a new connection or use the already opened one (opened by the session handler)? I have made it a good practice to close a connection after a query but if I do it with only connection open no session data will be written to my mysql table. I have seen some scripts using persistent connections but are not sure what would be the best for a real world environment.
View Replies !
Mail() Error Handling
I use mail() for a musician's mailing list script that suddenly started having problems after many months of working flawlessly. The code fragment is: if (mail($To,$Subject,$Body,$Headers,$Param)) { print("The message was sent to:<p>$HTML_BCC<br><hr><h3>Completed OK</h3><p> "); } else { print("<font color="#ccff66">There was a problem and the message was probably not sent.</font><br> "); } How can I find out what is causing the error? I thought there were built-in error number and error description messages, but a search of the manual at php.net does not come up with anything.
View Replies !
XSL Error Handling In PHP5
I`m need hanling XSLT errors in my script, before I`m use Sablotron, that has nice interface for it: ------------8<------------------ function ProduceXHTML($xml, $xsl){ $xh = xslt_create(); xslt_set_encoding ($xh, CODE_PAGE); $arguments = array('/_xml' => $xml, '/_xsl' => $xsl); $result = @xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); $this->error = (int)xslt_errno($xh); if($this->error){ $errorMessage = sprintf("Cannot process XSLT document [code %d]: %s", xslt_errno($xh), xslt_error($xh)); $this->AddErrorMessage(5, $errorMessage); } xslt_free($xh); } ------------8<------------------ but now I`m ported my project in PHP5 and use XSLlib like this: ------------8<------------------ function ProduceXHTML($xsltemplate){ $xh = new XSLTProcessor(); $xml = new DOMDocument(); $xsl = new DOMDocument(); $xsl->loadXML($this->LoadXSLT(TEMPLATES_ROOT.$xsltemplate)); $xml->loadXML($this->xml); $xh->importStyleSheet($xsl); $xhtml=$xh->transformToXML($xml); if($this->IsDebug()){ header('Content-type: text/xml'); die($this->xml); } if ($xhtml) { $xhtml = str_replace("&", "&", $xhtml); echo $xhtml; } else { /* commented, because PHPv5 used printf("Cannot process XSLT document [code %d]: %s", xslt_errno($xh), xslt_error($xh)); */ return false; // invalid XSL } unset($xh); } ------------8<------------------ anybody know how I can track errors now?
View Replies !
Custom Error Handling
I'm been looking at ways to add my own error handling capabilities to my PHP apps, but I'm not quite sure how to go about implementing it. For one, I only want to handle errors raised by trigger_error(), all others should be handled as normal by PHP, but this doesn't seem to be possible with set_error_handler(), if you do this, it seems you will have to handle ALL error types. Am I misunderstanding something here? Basically, I just want to have a handler for all errors created by trigger_error(), so whenever I call trigger_error(), I want my error handler to take care of it, otherwise I want PHP to print it's standard message.
View Replies !
Include Error Handling
I know this is really simple but have brain freeze. How do you include a page but include error.php (or any error file) if the file doesn't happen to exist.... for example include($page . '.php') //if page doesn't exist then... include ('error.php')
View Replies !
Handling PEAR::Error
My intention is to simplify our error handling. Sometimes I throw severe PEAR::Errors which must be logged and sometimes I throw less important errors, let's call them "warnings". How can I differ between warnings and errors? Both are thrown using PHP Code: return PEAR::raiseError("errormassage", MYCODECONSTANT); Am I forced to define errorcode ranges in order to check how important an error is? For example: All error codes from -1000 to -1999 would be warnings an all above would be "real" errors. I don't like this solution too much so maybe someone could give me a more sophisticated suggestion?
View Replies !
Error Handling For My SQL Queries
I'd like to set up some custom error handling for my php scripts. I see the string "or die(mysql_error());" at the end of each of my queries, so I figure there's a way to define a global error handling variable that can get put into this statement, I'm just not sure how to do it.. I just want to insert a line that tells the user of the error, and provides a link to the original page, so they can try again..
View Replies !
Mail Error Handling
Warning: Server Error in c:apachehtdocskeurslagerijverzonden.php on line 318 This is line 318 mail($email, $subject, $message, $headers);//sendmail to customer I know that the e-mail does not exists but is there something that gives a friendly error for the users?
View Replies !
Syntax Error Handling
When I run a PHP script on my server that contains a syntax error, it gives me no information on the error; no error handling or anything just returns this blank page: <html><head></head><body></body></html> always on one line like that. It's always done that. I have a Linux server. I've never changed any of the php.ini stuff. So unless my hosting company changed it, it should all be set to default values. Does anyone have any idea how I could get it to display a line number for syntax errors?
View Replies !
Need Php.ini To Enable Custom Error Handling
I'm trying to handle errors on my own. I copied this code from the PHP manual and pasted it at the top of my script, then took out a " from a string passed into a mysql_query(). Ran the script and still PHP outputed in its own message: Parse error: parse error, unexpected '"' in c:apachewwwfile.php on line 69 I wonder if there's something I need to do in the php.ini to enable custom error handling or something I missed out? PHP Code:
View Replies !
Error Handling With Remote Images
i'm making a random banner script that acquires the banner images remotely instead of being hosted in the own place. however, whenever the image cannot be acquired, i want to display a image saying "image missing" and not that ugly PHP warning that pops up whenever you put a non-existing image as the argument for getimagesize() Code:
View Replies !
API Style Error Handling For Forms
I've been working on an administration page that handles, admins and permissioned users. However I'm trying to create some sleek dynamic error handling that I can start to use across the rest of the site. I started by making a class that would handle the creation of basic inputs (i.e. textarea, inputbox, select) except I'm running into a problem when one of the fields is blank or is not in the right format. My question is there an easy way to implement errors for each input in a form. So if I have 15 inputs it checks 15 without me having to do if...else...if...else a billion times over. I was thinking of doing something with a true/false but wouldn't a true replace and false and false replace a true if they are all linked to the same variable. Code:
View Replies !
Elegantly Handling An Expected Error
I have a very modest database on my server and I use php to allow people to query it. Its very simple, they enter a value that should be in column 1 (account_num) and I return the value for column 2 (balance) (same row). Here is the question: What if the value they enter doesn't match any values in column 1? Right now, I get this ugly error message: Code:
View Replies !
Use Function In Class W/ Custom Error Handling
I'm trying to set a function that is held within a class as the custom error handler using the set_error_handler(), which takes the string name of the custom error function as its argument. I fully understand this, however, how do you use a function that is declared within a class? PHP Code:
View Replies !
Error Handling - Logging The URL Reported 'not Found'
The custom error page set up for my website is working fine, however I would like to try and take it to the next level. Is there a way to get the URL of the page that couldn't be found by either: a) what the user typed in the location bar b) the bookmark address c) link user clicked on (say from an old search engine listing) I performed a simple test using a plain HTML page with a link to a info.php page --[ echo phpinfo(); ] As best I could tell there is not a single environment variable that contained the URL that I clicked. There was of course HTTP_REFERER (the page it came from) and also REQUEST_URI. The problem with REQUEST_URI is that it pulls the URI of the error.php page, not of the actual 'bad link'. I've seen logs that list 'broken links' - I just don't know how to obtain that information.
View Replies !
Retain Form Variables After Error Handling
I have a form that only logged in users have access to that collects data about events. If the user submits the form and any data is missing or in error they get a message that there were errors or missing data and to please go back and resubmit the form. The problem is, when they click the back button they get an entirely blank form, all the data they entered is cleared. Code:
View Replies !
Exception Handling - Standardise Error Reporting Process
I work on a site with a large code base, for which which have our own error handling classes. We've decided to start using php5's exception handling mechanisms but as i look into it, i wonder when this is the right thing to do. We want to use it to standardise our error reporting process, and to make sure failed bd queries are logged. As i've started though i've realised... If i throw an exception in the DB class, and make the code using the class responsible for trying and catching, it means we'll have to go through the whole of our site adding try/catch blocks wherever we try and access the db. If we miss one, and at some point throw an exception, we'll get a fatal error which is the worst scenario. Alternatively we could make the DB class responsible for handling the whole situation as follows. Code:
View Replies !
How Do I Get PHP5's Exception Handling To Catch A Fatal Error?
Last weekend I decided to install Apache 2.0.53-win32-x86-no_ssl PHP 5.0.3 Smarty 2.6.7 MySQL essential-4.1.10-win32 I have Apache up (Port 80 blocked at the router and firewall!) and I have got Smarty working. I haven't got around to installing MySQL. I am now in chapter 8 'Error and Exception Handling' of "Beginning PHP 5 and MySQL: From Novice to Professional", by W. Jason Gilmore, pub. Apress. I tried example Listing 8-1. Raising an Exception: <?php //Boilerplate require('Smarty.class.php'); $smarty = new Smarty; $smarty->template_dir='C:php5includessmarty emplates' ; $smarty->compile_dir='C:php5includessmarty emplates_c ' $smarty->config_dir='C:php5includessmartyconfigs' $smarty->cache_dir='C:php5includessmartycache'
View Replies !
Handling Forms
Im trying to write a universal Formhandling function. IS there a variable as $formfields in Perl, that stores all the form fields in an array? In PHP as far as i got i have to write $name, $email and so on all the time and it takes a lotta work to costumize this for every form.
View Replies !
Handling Transaction
while updating my database (i am using mySQL) based on information provided by a user ..if due to some problems (say the server goes down .... electricity problems etc) half the entries have been stored and others aren't then i need to delete the entries how do i take care of that in php.
View Replies !
File Handling
How would I get my code to skip giving an error msg if no file exsists to open. Currently I'm using an IF statement, but it always gives the error of no file found anyways. Code:
View Replies !
Handling .xls Files With PHP - Can It Be Done?
Up until now, I have been importing data from Excel spreadsheets into MySQL by exporting them to either .csv files, or tab-delimited .txt files, then using PHP scripts to insert each row. This works fine, but just adds another step (open xls, save as csv, then import into MySQL). I am wondering, has there been any work done on handling xls files, natively, in PHP? The files I work with are very simple; just rows of data divided into columns. No cells are calculated based on the value of other cells. It is all text fields, with one field that holds a date value (not sure if Excel stores that as text or some sort of timestamp?). I am well aware of all the tools you can use to convert .xls to something else (e.g., OpenOffice), but I would like to do it *natively* in PHP, or at least using a program that I can kick off from within PHP. That way I can upload an .xls file, and let my scripts worry about converting it to something easily inserted in MySQL.
View Replies !
Session Handling?
I got this set of code out of a book to test if the session handling worked. It seems like creating a session ID works just fine, but nothing else works. The program is supposed to remember how many times you've watched the page, but it doesn't and it's supposed to remember you name if you insert it, but neither does that work. PHP Code:
View Replies !
Session Handling With Shm
Has anybody already tried to implement session handling with shared memory ? I just started to try and it seems to work out as a secure and very fast possibilty. Nothing else than the system id of the shm segment has to be passed, all the transaction data remains in the webservers main memory. 'Would be appreciated to receive or exchange any experiences!
View Replies !
Semaphore Handling
I m facing a memory related problem with semaphores. Our business application uses semaphores extensively and the limit imposed by the OS on the number of semaphores that can exist on the system is only 128. This could be increased to a higher value but that would not be a permanant solution to my belief. We are using the sem_get, sem_acquire php functions. After the use we are releasing the semaphore by using sem_release. The problem is that the semaphore will remain on the system until it is rebooted. And once the limit of 128 semaphores is reached, any attemt to create a new semaphore will result in a "No space left on device" error.
View Replies !
Php File Handling
I have designed a site which keep track of servers and their location (rack no.) in different datacenter. My rack number naming convention is like A1, A2, A3, A4,B1,B2 etc... I have some rack with the format like this MC01,MC02,MC03 and MC04 as well. I have draw my rack diagram normally to cover four racks. I named the file by using this naming convention A1-A4.png (cover the rack no from A1 to A4), MC01-MC04 etc. Each server will have a field inside the table to store the rack no. I want to link this information with the diagram I have. For example, when the user view a page like the following, he can click the download icon to download the corresponding rack diagram. Hostname Rack No. server1 A1 download server2 A2 download server3 A3 download If he click on the download link of A1, the file name that will be downloaded is A1-A4.png. My diagram filename covered range of value. Of course I can create individual diagram for each rack to solve this problem. I am not too sure what is the best way to deal with my problem.
View Replies !
PHP Handling Data
Consider the structure C:firstFile.php C:addsecondFile.inc.php A user comes and postes some data to firstFile.php . Then the file does a whole bunch of processing on the posted data. Now what should I do if secondFile.inc.php wants the same posted data. Is there anyway to make the posted data available to all the subfiles?
View Replies !
Array Handling
is html array is similar to php array, i have to pass a maltivalued array in the value of a button ,how can i accompolised this .
View Replies !
Form Handling With PHP
I have a bunch of pages with long forms, with lots of input types-text, radios, textareas, and the debugging process has become overwhelming. What I need to happen is to make sure that 1. Every field on the page is filled out-if not, a list of incorrect fields is displayed, and any radio boxes that were checked still are 2. The fields are queried to a table in a database. (The table has the same column names as the field names) Here's what I did; can someone tell me why this doesn't work? <?php require_once ('../mysql_connect.php'); $page_title = 'Test page' if (isset($_POST['submit'])) { // Handle the form. // Create an empty new variable. $message = NULL; // Create a function for escaping the data. function escape_data ($data) { global $dbc; // Need the connection. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string($data, $dbc); } //Create an array of all formfield names $required=array('field1','field2','field3'); //Check to see if all field names are filled in function field_check($required) { foreach($required as $q) { if(empty($_POST[$q])) { $message = 'Error: The following field was not filled in: $q' $ok=FALSE; } else { $ok; } } } // If no empty posts are returned if ($ok) { //set a variable for the current user $u = addslashes($_COOKIE['user_id']); //insert all variable values into the table foreach($required as $q) { $query = "INSERT INTO test_table ($q) VALUES ('$'.'$q')"; } // Run the query $result = @mysql_query ($query); // Run the query. // If it ran OK, write the the page with a link to continue. if ($result) { include ('templates/header.inc'); $page_title = 'Entry Recorded' echo "<p><b><a href="next_page.php" class="content">Continue</a>"; include ('templates/footer.inc'); exit(); // Quit the script. } // If it did not run OK, show an error else { $message = '<p>Your form could not be recorded due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>' } } // Close the database connection mysql_close($dbc); } include ('templates/header.inc'); // Print the error message if there is one. if (isset($message)) { echo '<font color="red">', $message, '</font>' } // Print the page. ?> <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"> <table> <tr> <td><input type="radio" name="field1" value="1"</td> <td><input type="radio" name="field1" value="2"></td> <td><input type="text" name="field2"></td> <td><textarea name="field3" rows="20" cols="30"> </textarea></td> </tr> </table> <p> <input type="submit" name="submit" value="Add to Record"> </p> </form> <? include ('templates/footer.inc'); // Include the HTML footer. ?>
View Replies !
Form Handling
I have a form: <form action="form.php" method="post"> <textarea cols="20" rows="20" name="words"></textarea><p> <input type="submit" value="check"> </form> I would like to have a php script that takes the value of $ydomains and breaks it up line by line and places each line as a value in an array. So if someone entered: apple baseball football An array called $words would look like: $words[0] = "apple"; $words[1] = "baseball"; $words[2] = "football"; How would this be done?
View Replies !
Exception Handling?
How do PHP folks deal with exception handling? try { .. block that may fail .. }catch($err){ .. clean up resources, etc.. } Is setting a die handler the only way to do this?
View Replies !
Event Handling
I have a calendar image which displays the date in a textbox when the event onclick is called. Is there any possibility of calling a php function (rather than using a submit button) at the same time, so that tha data from the database can be displayed..based on the value of textbox ?
View Replies !
Handling PDO Exceptions
I'm just starting to use PDO for the first time under PHP 5.1. But something doesn't work right in the following situation: try { $dbh = new PDO(...); ... } catch (PDOException $e) { print("Error!" . $e->getMessage()); die(); } If an error occurs in constructing the new PDO instance, e.g., because a wrong username/password, then the error is not printed. The application just dies. PDO works fine on my installation when there are no errors. What do I have to do to see the error message when a PDO exception occurs in such a try/catch block?
View Replies !
Handling Checkboxes
i have some problem handling with checkboxes when i try to insert a record.It returns no value. For example, if the student is enrolled to a course, i check the box and i want to store the value 1 and if the student is'nt enrolled, i leave the box empty. Well, i placed, if ($stdenrol=="") $stdenrol=0; before my insert st. <INPUT type=checkbox name="std_enrol" value="1"<? if ($stdenrol==1)echo "checked";?>> So, I think if the checkbox is checked, it returns a value "1" to the table and if it is not checked, it returns a value "0". If i check it and try to insert, it does'nt produce me any error.If i leave it empty, it produces me an error,"conversion error from string." How can i fix this error. This column can also accept null values.
View Replies !
Handling Images
I have the requirement to allow my users the ability to upload a file ... and attach the image to there profile. This is not something I am expeiranced in myself so I have security concerns. Researching on the internet I see some people have: allowed a user to just upload an image on the filesystem.or some people seem to encode images and put them into the database. Anyone have any preferences? Or have any reason to perfer one over another?
View Replies !
Forms Handling
I have a form that uses the database to display results, no issues there. However, I need to be able to acertain what the user has selected when the form has been submitted and I've been trying for about a week now to get the thing working. Code:
View Replies !
Memory Handling
i have a php script thats can run out of memory (basically the user overloads it), Now i plan to fix this but for now i wanted to manage the error, in my script i added <?php echo memory_get_usage()."-".memory_get_peak_usage(true)."<br />"; ?> into the loop and basically wanted to either handle the error or break the loop, but i can't seam to work out either 1. how to find the max amount of memory i can use or 2. capture the error. the error that displays is Quote578508-786432 1631084-6291456 2681008-11010048 3731308-15728640 4781348-20447232 5831764-25165824 Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 6297585 bytes) in /home/devico/public_html/class/UserExt.inc.php on line 150
View Replies !
|