Any way to change the formatting of the text and what is displayed after a die() command? I'm currently coding all my errors using die() but I'd like to have more control over how the error message is formatted and what is displayed afterwards (like a return link for example)

Any way to change the formatting of the text and what is displayed after a die() command? I'm currently coding all my errors using die() but I'd like to have more control over how the error message is formatted and what is displayed afterwards (like a return link for example)

One thing to bear in mind here is that die() is a language construct, not a function, but I think I see where you are going with this.

You could have a preset list of definitions for errors in the beginning of your script, then use them for your output. For example:

<?php

define("ERROR1", "Message for error number 1.");
define("ERROR2","A message with <a href='javascript:history.go(-1)'>a return to the previous page link</a> embedded.");

...

$filename = '/path/to/data-file';
$file = fopen($filename, 'r')
   or exit("unable to open file ($filename): ".ERROR2);

?>

This sounds like what you were looking for, but if I misunderstood, please feel free to clarify.

My 2¢. :)

One thing to bear in mind here is that die() is a language construct, not a function, but I think I see where you are going with this.

You could have a preset list of definitions for errors in the beginning of your script, then use them for your output. For example:

<?php

define("ERROR1", "Message for error number 1.");
define("ERROR2","A message with <a href='javascript:history.go(-1)'>a return to the previous page link</a> embedded.");

...

$filename = '/path/to/data-file';
$file = fopen($filename, 'r')
   or exit("unable to open file ($filename): ".ERROR2);

?>

This sounds like what you were looking for, but if I misunderstood, please feel free to clarify.

My 2¢. :)

Your 2 cents are work 2 billion :p Thanks a lot that is what i meant

die() is a fairly simplistic command. It puts a halt to script execution and echos the string in the argument.
I would recommend that you look into creating some custom error handlers at http://w3schools.com/php/php_error.asp.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.