Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2004, 06:56 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default Catch PHP error

Hi,

I posted this in HTML but looks like its a PHP issue.

I have an ‘issue’ with “catching an error”
In Visual basic, I can write down: on error goto xyz

Is there something I can do to catch the error bellow and redirect it to a webpage?

>> PHP Warning: POST Content-Length of 440912205 bytes exceeds the limit of 57671680 bytes in Unknown on line 0

As always, thanks for any help you can offer...


Snib already answered in the HTML forum:

This is a PHP error.

You can detect PHP errors with try {} catch() {} I believe, check out http://www.php.net

I've looked on php.net and .. .. I can't find a thing in there! :(
 
Old December 20th, 2004, 02:41 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Sorry, my bad. I thought you were trying to catch an exception.

Try http://us2.php.net/set-error-handler

-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old December 20th, 2004, 04:26 PM
Authorized User
 
Join Date: Dec 2004
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to colin.horne
Default

Hi

Don't quote me on this, but I think this is apache preventing large files from being uploaded.

I don't have time to look into it just now, but look in php.ini and/or httpd.conf to see if you can find the configeration option for setting max upload filesizes (likely google keywords: "max file size upload php").

Cheers

(Edit note - first search result yeilded http://uk2.php.net/features.file-upload, which seems useful)

--
Please contact me at:
Colin (dot) Horne (at) gmail (dot) com
 
Old January 7th, 2005, 08:25 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Colin, that won't do it; the max file upload is 2 MB (host server-not mine). I want to redirect the error message from the server so the users don't get that nasty message but a nice webpage teelling them what I think.. ;)
 
Old January 9th, 2005, 03:09 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Because this is an error stating that the lenth of POST content is exceeded, I don't think it is possible to "catch" this error. It is an error that happens *before* script processing begins, or at the very least is the first thing that happens when script processing does begin.

You can fake knowing about the error though. First, turn off error reporting. If you use Apache you can probably do this with a .htaccess configuration file. Then do normal validation in the script that processes the post data. If there is a lack of it (post data) then you know something went wrong with the submission and can alert the user to that affect, 1.) either nothing was submitted or 2.) too much was submitted.

If you're really determined to know when this particular error has been triggered, you can get into some nitty gritty error customization.

There are some functions outlined here:
http://www.php.net/manual/en/ref.errorfunc.php

Error handling can also be set as ini directives, which would be best in your case since the error in question is likely coming before runtime of your script.
http://www.php.net/ini_set

You need the ability to configure either httpd.conf or .htaccess of Apache to set ini directives without direct access to php.ini. As far as I know, this isn't possible with other HTTP servers.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old January 10th, 2005, 11:48 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<-Shot himself in the head

Why is it always so complicated (...)
 
Old January 10th, 2005, 12:13 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok.. 1st thank you for the reply.

I just checked the web and it looks easier than I first thought.
Can you show me an example on how to switch off error reporting?
Do I create a file called ".htaccess " ? I suppose we are speaking text file?

"normal validation in the script that processes the post data" now I know why you write books and I don't :)

Already have a bit of code checking if a problem occured when uploading / moving from temp to main directory.

I have a friend who's learning CSS; you must be a God for him ;) (http://tod.rsow.com/ that's one of his website.. won't have a clue if it's CSS or not to be honnest!)

Thanks for your help :)
 
Old January 19th, 2005, 01:05 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Hi, sorry for the belated reply.

Here's what my .htaccess looks like:
Code:
AddType application/x-httpd-php .html

php_value register_globals 0
php_value error_reporting 0
php_flag expose_php off
php_value session.gc_probability 75
php_value arg_separator.output &amp;
php_value arg_separator.input &;
php_value session.use_trans_sid off

php_value highlight.bg #ffffff
php_value highlight.comment #ff9900
php_value highlight.default #0000cc
php_value highlight.html #000000
php_value highlight.keyword #006600
php_value highlight.string #cc0000
Just some random configurations there.

If you're using Windows, you'll have to enclose the file name ".htaccess" in quotations while saving it. .htaccess configurations are also inherited to subdirectories, so if you place this in your top-level directory, scripts in the subdirectories should inherit the same configurations. (Assuming Apache was configured that way).

You can verify that the configurations have taken affect by running a phpinfo(); script in the same directory as the configuration file, .htaccess directives will appear under "Local value".

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design





Similar Threads
Thread Thread Starter Forum Replies Last Post
catch 404 error danielnixon ASP.NET 2.0 Basics 1 May 1st, 2008 06:57 PM
Unable to catch error HttpException (0x80004005): Shibu General .NET 6 May 22nd, 2007 04:21 AM
Catch POST error ? Mantis HTML Code Clinic 1 December 18th, 2004 06:37 PM
Catch and display an appropriate error nambati General .NET 3 December 16th, 2004 11:00 AM
How to catch error. lancet2003 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 December 3rd, 2003 02:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.