SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I detect missing PHP code

    On occasion, a PHP file inadvertently gets replaced on the server with the generated HTML, such that the page is no longer dynamic (but still has the .php extension).

    Is there an easy way for PHP to be configured to check for a .php file with no actual PHP code when the server serves the page and notify the webmaster by e-mail of this issue?

    The only other thing I can think of is to run a cron job periodically that will scan all of the .php files for this issue.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Don't you think you should find the cause of it and fix that?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have investigated the problem and that solution is not currently available.

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    logic_earth is right, you need to explain to the client/whoever is overwriting pages that the system is broken. Duct taping things won't help in the long run.

    Anyway ... duct tape

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Location
    in the eyes of a madman
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cache problem?

  6. #6
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, You can not detect missing php code, but you can find error when you will run that code, the error will display if any code or syntax is missing in your php file. if you want to identify syntax error then it use dreamweaver.

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no error in the page. The page displays just fine. It's just that the visible content is wrong because there is no PHP code.

    But, given there is no way to detect this at serving time, it appears I'll just have to cron a job that checks that updated PHP pages still have PHP code.

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could read the file contents and look for a <?php tag
    see file_get_contents() and strpos()

  9. #9
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's pretty much what I plan to do, and then send an e-mail if it doesn't contain "<?php", thanks.

  10. #10
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Charles Belov View Post
    But, given there is no way to detect this at serving time, it appears I'll just have to cron a job that checks that updated PHP pages still have PHP code.
    Quote Originally Posted by hash View Post
    Anyway ... duct tape
    why wouldn't that work at serving time???

  11. #11
    SitePoint Guru
    Join Date
    Oct 2008
    Location
    Melbourne
    Posts
    754
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Charles Belov View Post
    On occasion, a PHP file inadvertently gets replaced on the server with the generated HTML, such that the page is no longer dynamic (but still has the .php extension).
    Honestly, I think *this* is the problem. What is overwriting your files?
    "I'm Commander Shepard, and this is
    my favourite post on the internet."

    We'll miss you, Dan Schulz.

  12. #12
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree it's a problem, but I don't have access to the code that is causing the problem.

  13. #13
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    San Francisco
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hash View Post
    logic_earth is right, you need to explain to the client/whoever is overwriting pages that the system is broken. Duct taping things won't help in the long run.

    Anyway ... duct tape
    Thanks for the reference. I'll see whether that particular feature would help. I have reported the problem but in the meantime I do need some form of duct tape.


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
  •