Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    die function Witch way?

    Hi
    i been watching tutorial after tutorial, and a lot of them been saying its better to make your die function nice and clean. Also doing so will help secure your script better is this true? should i go with Option (1) or Option (2)
    PHP Code:
    //Option (1) Clean die function:
    die();
    //Option (2) Way i have it to show any errors die function:
    die('Error in query:<br>'$sql .'<br>'.mysql_error($conn).'<br>Time of Error: '.date("l F j, Y, G:i:s T")); 

  • #2
    New Coder
    Join Date
    Sep 2011
    Location
    Blackpool
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Quote Originally Posted by ycpc55 View Post
    Hi
    i been watching tutorial after tutorial, and a lot of them been saying its better to make your die function nice and clean. Also doing so will help secure your script better is this true? should i go with Option (1) or Option (2)
    PHP Code:
    //Option (1) Clean die function:
    die();
    //Option (2) Way i have it to show any errors die function:
    die('Error in query:<br>'$sql .'<br>'.mysql_error($conn).'<br>Time of Error: '.date("l F j, Y, G:i:s T")); 
    Adding in a die option and giving it parameters will just allow to you to know where your code is failing.
    P.s You put Witch instead of Which in your title;p
    Subscribe to a channel dedicated to helping people learn HTML, PHP & CSS.
    http://www.youtube.com/user/RanTutorials

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,436
    Thanks
    13
    Thanked 360 Times in 356 Posts
    Quote Originally Posted by ycpc55 View Post
    Hi
    i been watching tutorial after tutorial, and a lot of them been saying its better to make your die function nice and clean. Also doing so will help secure your script better is this true?
    IMO, die() makes your page primarily invalid. either you send (no) text where there should be full HTML page or a truncated HTML page. neither is what the user expects to see.

    additionally, debugging info is not supposed to get public. you’d better logging that or sending yourself an email of it (or do both).

    if a critical error occurs, send the user an error page to explain that something happened that out of the regular.

    and therefore I’m a fan of exceptions.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #4
    New Coder
    Join Date
    Jan 2007
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks for the help guys.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •