Web Analytics Made Easy -
StatCounter Having the damndest time trying to find an error in a php file - CodingForum

Announcement

Collapse
No announcement yet.

Having the damndest time trying to find an error in a php file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Having the damndest time trying to find an error in a php file

    Hi folks,

    I don't have access to the php.ini file in a site I am working on at the moment so I tried using
    php_flag display_errors 1
    in the .htaccess file and it caused the index page of the site to not work(!) which was not the one I was trying to find the error in.

    That is one issue that cropped up... the issue I am trying to resolve is where I am using a download script here: http://67.211.218.91/podcast-listings.php to download podcasts from the site. Everything seems to work OK right up until one clicks 'Save' in the Windows Explorer window that pops up as to where one wants to save it to. That's when the error makes itself known. When the download attempts to start it comes up with an error in the bottom left corner of the browser's window (on the status bar) saying 'Failed - Network error'.

    To try and figure out if it was an actual server configuration error I created a test folder http://67.211.218.91/test/, put an audio file in there and then tried downloading it. It worked fine. Which completely stumped me. I have used the same configuration of the actual file I want to use (podcast-listings) from another of my sites which is coded in a very similar way, compared the two and couldn't find anything different.

    So I then tried to add the error code to the .htaccess file which is where I found I couldn't even get that to work. What else can I do to get ALL the errors to display so that I can determine where the problem is? And what do I need to post here (in terms of code) to get someone to look at the code if they are willing to help? The entire code is code over 4 pages (template code). Zip up these pages and post them here? Or...?

  • #2
    @judgedredd,
    I don't have access to the php.ini file in a site I am working on at the moment so I tried using
    php_flag display_errors 1
    in the .htaccess file and it caused the index page of the site to not work(!) which was not the one I was trying to find the error in.
    Instead of trying to set error reporting in .htaccess try the following:
    file: index.php
    Code:
    <?php declare(strict_types=1); // file wide only
    error_reporting(-1); // maximum errors
    ini_set(‘display_errors’, ‘true’); // show on screen

    Comment


    • #3
      Hi John_Betong , ok, I will try that.

      Note: I was able to access the php.ini settings and the display_errors was already set to on. Very odd that it didn't show anything.

      Comment


      • #4
        Originally posted by judgedredd View Post
        Hi John_Betong , ok, I will try that.

        Note: I was able to access the php.ini settings and the display_errors was already set to on. Very odd that it didn't show anything.
        I endeavour to always have display_errors on in the php.ini file and errors and warnings are logged. Did you check the error log?

        /var/log/apache2/error.log // Ubuntu log file, may vary for other operating systems.

        On my system I have more than one PHP version and each has their own php .ini file. I hope you checked the relative php ini file

        From memory the call to check the PHP version is phpversion();
        Last edited by John_Betong; Sep 5, 2021, 08:08 PM.

        Comment


        • #5
          Well, adding that code to the top of the page caused it to throw a wobbly. See screen shots of before and after:

          Click image for larger version

Name:	ss1.jpg
Views:	48
Size:	98.4 KB
ID:	2432937

          Click image for larger version

Name:	ss2.jpg
Views:	49
Size:	79.5 KB
ID:	2432938

          Bear in mind that this is the page that is part of the template system.

          Comment


          • #6
            I only have one PHP version as it is the only site on the server. Its version 7.4.21

            Comment


            • #7
              Did you check the error.log file?

              The following errors are shown when I try to download a mp3 file:


              This site can’t be reached

              The webpage at http://67.211.218.91/podcast-listing...+June+2019.mp3 might be temporarily down or it may have moved permanently to a new web address.

              ERR_CONTENT_DECODING_FAILED
              Edit:
              I tried without success on the original site and didn’t even get a redirect or splash screen?

              https://freshoilreleases.co.za/
              Last edited by John_Betong; Sep 5, 2021, 08:47 PM.

              Comment


              • #8
                I got it to work in the end with a crude hack until I figure out what is wrong. I used a required file and did a sitelink code. Here is the code for index.php (inside a folder called 'library'):
                PHP Code:
                <?php
                include('libs/startup-listing.php');
                template_header();
                require(
                "xyz.php");
                ?>

                <section>

                <iframe src="<?php echo SITELINK?>"frameborder="0" width="100%" height="3650" scrolling="auto">
                </iframe>

                </section>

                <?php template_footer();
                and here is the xyz.php file:
                PHP Code:
                <?php

                define 
                ('SITELINK''http://67.211.218.91/library/index.php');

                ?>
                I will check on the error log stuff another time. As I have it up and running (sort of) I am going to take a break. As to typing in the domain, browsers are now saying that the site can't be reached. You can - all you have to do is go into the address bar and delete the http:// or https:// bit.

                Comment


                • #9
                  I had the same problem before when I try to do a download from my test environment (localhost).

                  If I remember it right, Firefox is okay, Chrome says network error, I think both safari and IE were also dying.

                  My project redirects from http to https. It turned out that the network error I was getting was that, because I was using a self signed certificate. I think it is because the browser has no means to ask you if you want to continue.

                  Forcing the site to use http only (no https redirect), All browsers were happy.

                  Comment


                  • #10
                    Thanks josephm . I hadn't thought of that. There is an odd thing that has been happening, and its only with this site that the issue has been occuring out of all those I have done, and its this: when the domain is typed into the browser (freshoilreleases.co.za) sometimes all that appears is a random string of numbers. Then what one has to do is go to the address bar and remove the stuff in front of freshoil, i.e. the http://www. or https://www. bit . Its very annoying as no other sites where I have had the direct IP appear in the browser has this issue. So you may have pointed out the item I have to resolve. Thanks again.
                    Last edited by judgedredd; Sep 9, 2021, 04:30 AM.

                    Comment


                    • #11
                      Silly question on my part but... did you bother looking at your php error logs?

                      Oh and John_Betong if he didn't write the code for strict typing, forcing it is just going to make MORE errors, not less.
                      Walk the dark path, sleep with angels, call the past for help.
                      https://cutcodedown.com
                      https://medium.com/@deathshadow

                      Comment


                      • #12
                        Originally posted by deathshadow View Post
                        Silly question on my part but... did you bother looking at your php error logs?

                        Oh and John_Betong if he didn't write the code for strict typing, forcing it is just going to make MORE errors, not less.

                        I reckon it is preferable to be aware of every error and warning rather than code in blinkers/blinders.

                        Once known errors can usually be suppressed by prefixing PHP functions with an @, also enclosing some script between error_reporting(0); …dodgey script… error_reporting(-1); will prevent raising any errors and/or warnings.

                        Using validation and rectifying all errors and warnings is well worth the additional effort.
                        Last edited by John_Betong; Sep 7, 2021, 08:16 PM.

                        Comment


                        • #13
                          Your site has numerous security vulnerability's which include XSS, Path Overwriting, Script source code disclosure and more.

                          Look familiar?
                          PHP Code:
                          CONFIGURATION
                          =============
                          Edit the variables in this section to make the script work as
                          you require. 
                          To save time, lets just assume I am almost never wrong.

                          The XY Problem
                          The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

                          Make A Donation https://www.paypal.me/KevinRubio

                          Comment


                          • #14
                            Originally posted by benanamen View Post
                            Your site has numerous security vulnerability's which include XSS, Path Overwriting, Script source code disclosure and more.

                            Look familiar?
                            PHP Code:
                            CONFIGURATION
                            =============
                            Edit the variables in this section to make the script work as
                            you require. 
                            [off-topic]
                            I’m interested in site security and no doubt others would also like to learn. May I suggest creating a new Security Topic… or point towards some simple tutorials.

                            I appreciate a simple search will reveal numerous links, I would like to know any you recommend to get started.
                            [/off-topic]
                            Last edited by John_Betong; Sep 7, 2021, 10:21 PM.

                            Comment


                            • #15
                              Hi guys. Thanks for everyone's input. I have been able to locate the error log (as I couldn't find it at first) and its over 40MB in size! From what I remember ( typing this on my iPad after turning my work computer off hours ago) that was only two or so days worth. There are two sessions being called at the same time - one is in @deathshadow's original template files and the other is being called by the blog script (which is on the index page). There or one or two constant errors in the template code as well. So I will eliminate one of the session codes and work on the others one by one.

                              benanamen, how can I make the environment more secure (not including using https)?

                              As to the original problem, I have kept the crude hack intact for the time being and cleaned up the styling of the page as much as possible, though I forgot to use Firefox to test the responsiveness of that page in mobile devices. As I go through the error log I will eventually get to the place where the error that I am looking for is being thrown up.

                              One thing that I discovered is that iOS really renders the page differently when one clicks on an mp3 file. Instead of giving a download dialogue box that section of the page turns black and in the middle of it (vertically) a very thing line appears that turns out to be a control for an audio player, and tapping on what looks like a play arrow, the audio starts to play on the page. Not ideal. I had no idea that iOS is so damn crappy when it comes to following php, html5 and css3 protocols.

                              Comment

                              Working...
                              X