CodeIgniter Forums

Full Version: BUG in Input.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Why do you send a float value as expire? Huh
It is bad design to force the variable to change the type. The best way is too show an error.
It's not a bug you're passing invalid input. Why are you using a float?

Code:
    /**
     * Set cookie
     *
     * Accepts an arbitrary number of parameters (up to 7) or an associative
     * array in the first parameter containing all the values.
     *
     * @param    string|mixed[]    $name        Cookie name or an array containing parameters
     * @param    string        $value        Cookie value
     * @param    int        $expire        Cookie expiration time in seconds
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.
(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:


   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.

So stop passing it floats, you're not supposed to do that.
(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 

<
div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">



<
h4>A PHP Error was encountered</h4>



<
p>SeverityWarning</p>

<
p>Message setcookie() expects parameter 3 to be integerfloat given</p>

<
p>Filenamecore/Input.php</p>

<
p>Line Number361</p


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))
        {
            
// always leave 'name' in last place, as the loop will break otherwise, due to $$item
            
foreach (array('value''expire''domain''path''prefix''secure''httponly''name') as $item)
            {
                if (isset(
$name[$item]))
                {
                    $
$item $name[$item]; // the new $expire value is being set here.
                
}
            }
        } 



PHP Code:
if ( ! is_numeric($expire))
        {
            
$expire time() - 86500;
        }
        else
        {
            
$expire = ($expire 0) ? time() + $expire 0;
        } 



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,[bintval($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.
(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
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.

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.
(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.
(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."

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.

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.
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
$twoMonths =   60      60     24   *  60     time();