SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: "Die" problems

  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy "Die" problems

    Dear everyone,

    I've been adding customized error messages to my page using the "die" function of PHP. Currently my "include" function looks like this:
    PHP Code:
    <?php include([url=http://www.cybercory.net/php-bin/styling.php]http://www.cybercory.net/php-bin/styling.php[/url]) or die(header("location:http://www.cybercory.net/php-bin/error.php?type=include" ));?>
    Is it possible to use the "header" function within the "die" function? Thanks for your help.

    Compuwhiz7

  2. #2
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't think so, I would rather just do if (include fails) {
    header(some location);
    exit();
    }
    - website

  3. #3
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHP.net Manual
    Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
    So in other words, if anything is sent before the header() function, it won't work. If your include() fails, data's still sent to the browser first I think, so I don't think it will work.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  4. #4
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could take a look at this: http://is.php.net/manual/en/ref.outcontrol.php
    - website

  5. #5
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Aes
    So in other words, if anything is sent before the header() function, it won't work. If your include() fails, data's still sent to the browser first I think, so I don't think it will work.
    If you've sent any, sure, but not as a consequence of include() failing.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  6. #6
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by compuwhiz7
    Dear everyone,

    I've been adding customized error messages to my page using the "die" function of PHP. Currently my "include" function looks like this:
    PHP Code:
    <?php include([url=http://www.cybercory.net/php-bin/styling.php]http://www.cybercory.net/php-bin/styling.php[/url]) or die(header("location:http://www.cybercory.net/php-bin/error.php?type=include" ));?>
    Is it possible to use the "header" function within the "die" function? Thanks for your help.
    You're missing a quote.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  7. #7
    SitePoint Enthusiast Igloo's Avatar
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If an include fails it will send HTML input to the browser, thus the header() function will fail.

    Speaking from personal experience, of course

    Igloo...

  8. #8
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Igloo
    If an include fails it will send HTML input to the browser, thus the header() function will fail.

    Speaking from personal experience, of course

    Igloo...
    It still sends the warning/notice/whatever even with an or?
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  9. #9
    SitePoint Enthusiast Igloo's Avatar
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, just tested it out to make sure. It still, with an or will return an error.

    Igloo...

  10. #10
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did also. Strangely, prepending @ to the include call supresses the die() also.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  11. #11
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    Thanks for your help. The problem is solved.

    Cory


Bookmarks

Posting Permissions

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