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 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Checking page size/whether image exists.

    Hello,

    I have a php program running that can generate content and populate a page with different content based on many factors. However, there are certain circumstances where a blank page may be generated. Without going into the scope of the entire project, I want to know if it's possible that when my php page loads, I can 'check' to see if the page is blank, or 'check' to see whether a particular image has loaded, and if the page is blank or no image loaded, redirect to a new page.

    Is there any way to do this? A function that can read the size of the current document would probably be sufficient.

    Thanks!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can use output buffering to accomplish this. Start output buffering at the top of the script using ob_start(), then after the page is built you can us ob_get_contents() to parse what was built, look for an image, etc. etc. then ob_flush() or redirect based on what you find.

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Blank pages are generally the result of a fatal error that isn't shown because you have error reporting off. You don't need to do any checking, just fix the underlying problem.
    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors'1); 

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    I think rather than trying to figure out if a page is blank, why not keep track of those things with variables?

    I'm assuming the page is supposed to load 1 or more things, and you don't know right now how many things loaded. And so if the page is empty go somewhere else.

    You will have to explain more of the project in order to get a good answer.

    Checking the output of the page is not a good method to see whether the page is "empty".

  • #5
    New Coder
    Join Date
    Apr 2006
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hello,

    Thanks for the help so far. Not displaying an image is not the sign of an error in this particular project. The scope of the program is basically a gallery, and there are certain photos in certain spots that I will be adding. But for the time being, some of the records will be empty. There is a button to go to the next or previous record, however it stops at a record even when it is blank. What I want to do is if the image is not yet found, skip it and continue cycling records until it hits one that is populated.

    Now the image is the only thing that displays on the page, other than the next and previous buttons so the document size will be very, very small if the image does not load.

    I do see the reccomendation above and I'm going to try to work with it but I am unfamiliar with that function. If anyone can give any code examples or another method it would be appreciated. Thanks!

  • #6
    New Coder
    Join Date
    Apr 2006
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hello,

    Am still looking to resolve this issue if anyone can help.

  • #7
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    A function that can read the size of the current document would probably be sufficient.
    You can only read the current output that PHP is ready to send to the user.

    You cannot detect what images are loaded, how much data the user actually received.

    Those things would be in the realm of JavaScript.


  •  

    Posting Permissions

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