![]() |
BUG in Input.php - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: BUG in Input.php (/showthread.php?tid=65944) |
BUG in Input.php - agdsys - 08-14-2016 I found in my log the following warning message: temporary solution: ERROR - 2016-08-14 00:12:25 --> Severity: Warning --> setcookie() expects parameter 3 to be integer, float given /home/www/html/basicapp/system/core/Input.php 410 1- input.php class inherit MY_input.php 2- copy the method set_cookie () 3- to force the variable expires (int) $ expires 4- waiting for the correction or corresponding recommendations. I am using CodeIgniter 3.1.0 + PHP 7.0.8-0ubuntu0.16.04.2 best regards. RE: BUG in Input.php - Paradinight - 08-14-2016 Why do you send a float value as expire? ![]() It is bad design to force the variable to change the type. The best way is too show an error. RE: BUG in Input.php - spjonez - 08-15-2016 It's not a bug you're passing invalid input. Why are you using a float? Code: /** RE: BUG in Input.php - agdsys - 08-15-2016 thanks for the comments, however, I am case observing the types of data according to the specifications of set_coockie method and detected in the area: if ( ! is_numeric($expire)) { $expire = time() - 86500; } else { $expire = ($expire > 0) ? time() + $expire : 0; } here -> $expire is floating rate, try it yourself. setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly); the result is a floating rate and not a whole as REQUIRES native php function. http://php.net/manual/es/function.setcookie.php have a nice CodeIgniter. RE: BUG in Input.php - Narf - 08-16-2016 (08-15-2016, 06:46 PM)agdsys Wrote: thanks for the comments, however, I am case observing the types of data according to the specifications of set_coockie method and detected in the area: So stop passing it floats, you're not supposed to do that. RE: BUG in Input.php - giggle - 11-05-2016 (08-15-2016, 07:37 AM)spjonez Wrote: It's not a bug you're passing invalid input. Why are you using a float?It's a bug.I'm getting the exact same error, in the exact same lines, and not passing anything different from whatever is already written in the code. (new push on GitHub doesn't fix): PHP Code: General ajax request failed : parsererror - I "fixed" the problem in my code by adding an intval wrapper around the $expire parameter in the setcookie: 2956735888 You can see that value is too big to be an int, so it's interpreted as a float. It's too big because in this line $expire is a sum of time() + $expire = 2956735888. Example: 1478364965 + 1478372165 = 2956729930. It's being set in the foreach loop: PHP Code: if (is_array($name)) PHP Code: if ( ! is_numeric($expire)) In fact, $expire doesn't seem to be even passed to the function set_cookie, so it's being default set to ''. PHP Code: setcookie($prefix.$name, $value,[b] intval($expire)[/b], $path, $domain, $secure, $httponly); You have other choices here. You can simply change PHP Code: $expire = ($expire > 0) ? time() + $expire : 0; to PHP Code: $expire = ($expire > 0) ? $expire : 0; But that just means the cookie will expire now. you can add some timeout value in seconds to the $expire: PHP Code: $expire = ($expire > 0) ? 86400 + $expire : 0; // 86400 is 24 hours It's this last modification that I am using. RE: BUG in Input.php - spjonez - 11-07-2016 (11-05-2016, 10:11 AM)giggle Wrote: I "fixed" the problem in my code by adding an intval wrapper around the $expire parameter in the setcookie: 2956735888 What is the exact value you are passing as expire? time()? If you're overflowing an INT you're doing something wrong. PHP Documentation Wrote:The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18, except on Windows prior to PHP 7, where it was always 32 bit. PHP does not support unsigned integers. RE: BUG in Input.php - giggle - 11-07-2016 (11-07-2016, 06:40 AM)spjonez Wrote: "What is the exact value you are passing as expire? time()? If you're overflowing an INT you're doing something wrong." This is the problem with so many responses to the original question. It's not what "I" am doing, it's what CodeIgniter is doing. I'm merely validating what the OP posted, because I got the exact same error in the exact same lines of stock CodeIgniter code. I did nothing but install CodeIgniter to get the error. I posted a solution, a solution that i working for me. RE: BUG in Input.php - Narf - 11-07-2016 (11-07-2016, 06:50 AM)giggle Wrote:(11-07-2016, 06:40 AM)spjonez Wrote: "What is the exact value you are passing as expire? time()? If you're overflowing an INT you're doing something wrong." So, you just "installed" CodeIgniter, and it called itself with wrong parameters? Are you sure? Are you really, really sure? Unless that is so, you cannot claim that you're faultless and blame it all on the framework. RE: BUG in Input.php - InsiteFX - 11-07-2016 If you read up on cookies you would see that setting the cookie expire time like below: PHP Code: // seconds * minutes * hours * days + current time |