IT.COM

PHP upgrade 5.3 > 5.4.20 Something broke

Spaceship Spaceship
Watch
Impact
11,350
I'm trying to kill a bug which has appear after I upgraded to PHP 5.4.20. I have no idea if this is a known problem or not. It's to do with the listing of files to download. I get the following error message when listing each line for each file to download, and the download link is broken.

Strict Standards
: Only variables should be passed by reference in /filelocation/index.php on line 50
The error message is referring to this line, as far as I can tell....

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

Is this something that could have been obsoleted with the upgrade. Is there maybe an upgrade which I should point to instead?

Is this something I could correct by using less Strict Standards? How to do that?

Any help or useful ideas. I'm not an expert in PHP and know nothing about javascript.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
0
•••
Disabling strict standard is an option but ideally it would be to fix that code at line 50. You likely have some function there. Check what is passed to it and how is the function header defined. References have & symbol before it.
 
0
•••
OK. So the first thing I've done is upgrade my jquery to the latest

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

The first error at line 50 is resolved, but I'm now getting an error at line 100. It's the same error message as above and refers to this line

$filetype = strtolower(end(explode('.',$fetchFiles->filename)));;

What is the non-variable in this line, and how to correct it? Do I need to define something here as a variable? How to do that? Where to put it? This is not my code but I'd like to correct it.

As before, any help would be greatly appreciated.
 
0
•••
Remove the extra semi-colon :)
 
0
•••
$filetype = strtolower(end(explode('.',$fetchFiles->filename)));;

What is the non-variable in this line, and how to correct it? Do I need to define something here as a variable? How to do that? Where to put it? This is not my code but I'd like to correct it.

As before, any help would be greatly appreciated.

you just need to put an extra var there so it can be then passed to the "end" function:

$filetype = explode('.',$fetchFiles->filename);
$filetype = end($filetype);
$filetype = strtolower($filetype);

should do the job

the problem is you are passing a non-var parameter to the function that is supposed to change it. that triggers Strict error. until you turn Strict reporting off you'll keep getting them unless you inspect all your code and fix those things everywhere. which can be a tough task to accomplish depending on the amount of code..
 
1
•••
Thanks @4pm - That fixed it up thanks. I'm still getting errors in another file. I've posted the code below.

Thanks @IceDude - I removed the semi-colon by replacing the whole line with 4pm's code :)
 
Last edited:
1
•••
Here is the code in download.php which triggers the additional errors...

Line 17: $errflag = false;
Line 18:
Line 19: if(!$_GET['file']) { $errmsg_arr[] = 'No file selected'; $errflag = true; }
Line 20:

Here are the errors and warnings...

Strict Standards: mktime:)( You should be using the time() function instead in /filelocation/download.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at /filelocation/download.php:17) in /filelocation/download.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at /filelocation/download.php:17) in /filelocation/download.php on line 19

Warning: Cannot modify header information - headers already sent by (output started at /filelocation/download.php:17) in /filelocation/download.php on line 20
 
0
•••
Can you give a link to the file?
 
0
•••
You clearly did not write the code.
You should get support from wherever the code came from.

If you can't get support then you should consider upgrading / changing to something else. I'm guessing the code hasn't been updated in a long time.

5.3 has reached EOL.. Why stop at 5.4?
 
1
•••
I actually like the method I'm using to distribute some software. I think if I can spend a few hours debugging the bugs, it beats out the weeks it would take researching trialling and eventually deciding what to replace it with. And them implementing it. 2 bugs beaten, and I think this last bug will be the last bug to fix. PHP has been very stable software with supporting previous versions. I've never before experienced any problems upgrading my PHP software. This Strict Standards change/implementation should be easy enough to figure out and fix for a PHP programmer, which I am not. But I can read (some) and edit (most) code.

Your suggestion to contact the original author is a good one. I have reached out to him, but I'm not very hopeful since there hasn't been any activity in his support thread for 2 years. Probably because, like me, everyone has been very happy with his script. We shall see. In the meantime, if anyone has any thoughts on how to fix this Strict Standards problem, it will probably fix the warnings also.
 
Last edited:
0
•••
I actually like the method I'm using to distribute some software. I think if I can spend a few hours debugging the bugs, it beats out the weeks it would take researching trialling and eventually deciding what to replace it with. And them implementing it. 2 bugs beaten, and I think this last bug will be the last bug to fix. PHP has been very stable software with supporting previous versions. I've never before experienced any problems upgrading my PHP software. This Strict Standards change/implementation should be easy enough to figure out and fix for a PHP programmer, which I am not. But I can read (some) and edit (most) code.

Your suggestion to contact the original author is a good one. I have reached out to him, but I'm not very hopeful since there hasn't been any activity in his support thread for 2 years. Probably because, like me, everyone has been very happy with his script. We shall see. In the meantime, if anyone has any thoughts on how to fix this Strict Standards problem, it will probably fix the warnings also.

What is the script? Or is that being too nosy?

Usually if there is a support thread you should post something there because if the script is in use you will very quickly find out that others are having the same issue. It's really the best way to stay on top of a developer - and then perhaps more importantly - let people direct you to equivalent/better/alternative solutions that achieve the same thing. It's very common to see forks established (depending on licence) and become more popular than the original :)

I decided to look into Laravel by the way (from your other post)- I didn't really think much about it but I've read some good things.
 
0
•••
It's by a guy who runs phux.org, but as I said, I haven't seen any posts since 2012 (apart from mine) :) It's simply called Download Manager on his website. It was free. Not that I wouldn't have paid some money for it. I don't know how I found it originally, I would guess by a Google Search. I'd really like to continue using it because finding something else I like, I know is going to be a hassle. Also it looks like I'm almost there with the debugging.

Laravel seems to be trending more and more popular. I could specify it for use in developing one of my websites, not developed by me.
 
Last edited:
0
•••
0
•••
Stu,

i dont see any mistakes in those 4 lines of code you posted. Headers already sent means your script is sending HTTP headers somewhere in the code and then is trying to change them (or send again) during the execution of download.php - which cant be traced down without examining download.php and probably all the files that call it...
If you got access to php.ini (might be not allowed on shared hosting) you would just add

error_reporting = E_ALL &~E_NOTICE &~E_STRICT

to the end of the php.ini file.
If not try to put

error_reporting(E_ALL &~E_STRICT &~E_NOTICE);

at the very beginning of download.php (or if you have a single entry point to your php files via index.php - put it there at the 1st line, i dont know what your app structure is, normally everything goes thru index.php so other executables dont get called directly via HTTP request to .php file)

That should suppress (still depending on many other php/webserver/app settings) Strict mode errors.

Ideally you need to clean your code up to comply with new 5.4/.5/.6 deprecated/error reporting things - hopefully there are just a couple of header sent problems left, otherwise you'll need to hire someone. If the project is not big, that wuld not be expensive to accomplish - there are not too many things that are not back compatible with 5.3 in 5.4 (in fact nothing, thats just changes in error reporting level and a couple of deprecation alerts that still work ok is what causes your problems), errors like "Headers already sent" or "Only variables should be passed by reference" are relatively easy to debug and fix.
 
1
•••
OK. I understand. But I think the warnings will go away after I fix the Strict Standards error. Yes/No? I'm reluctant to switch off the Strict. I'd prefer to fix the error if possible. But I try your suggestions and let you know. I'm on a VPS, so shouldn't be a problem.
 
0
•••
But I think the warnings will go away after I fix the Strict Standards error. Yes/No?

If the script worked OK on php 5.3 with no errors during runtime, they should go away if you turn off Strict reporting cause formally speaking they are not errors but deprecation alerts meaning to tell you some coding patterns in your script is now considered not good for some reason. Those patterns (particularly passing non-vars to functions) will still work OK but that may change with new php releases. So ideally - yes, fix them all. But if you need fast temp solution that keeps the things running unless you debug all the errors suppressing Strict reporting should work for you..

I'm on a VPS, so shouldn't be a problem.

yes, try to edit php.ini
to figure out which php.ini files are in use by your installation (usually there are many those php.ini in various dirs depending on OS and php version) create a file phpinfo.php in your web root directory, put

<?php phpinfo(); ?>

in it and point your browser to yourdomain/phpinfo.php
(if you route incoming http requests somehow you may need to add a path to phpinfo to your routing routines, depends on your app settings)
remember that simply calling "php --ini" from a command line will give you only CLI settings which is not what you want in this case..
 
0
•••
You should fix the SQL Injection issue that is reported online too.
 
0
•••
0
•••
@4pm - I thank you very much for all your help. I put your suggestion into the download.php file and now everything working fine again. I'm a happy camper :) You were right on the money with all your suggestions.

The script worked fine in 5.3. But I would still prefer to fix the error, if possible...

Strict Standards: mktime:)( You should be using the time() function instead in /filelocation/download.php on line 17

Should I just remove "mk" out of "mktime"?
 
0
•••
OK. I removed the strict suppression and deleted the "mk" out of "mktime" and all errors now gone and download proceeds. Thanks everyone and especially 4pm.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back