Codeigniter version 3.0.3 and PHP version 7.2. I have installed Ubuntu 18.04 Server OS with mysql,php and apache2. When I am running the codeigniter project in localhost, it works fine but not in the server. It loads the login page but does not redirect to given page, it just refreshes the login page when valid credentials are provided. Help to solve this if somebody knows the issue.
Error when loading index page in the server
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: sizeof(): Parameter must be an array or an object that implements Countable</p>
<p>Filename: controllers/Login.php</p>
<p>Line Number: 57</p>
<p>Backtrace:</p>
<p style="margin-left:10px">
File: /var/www/html/sample/application/controllers/Login.php<br />
Line: 57<br />
Function: sizeof </p>
<p style="margin-left:10px">
File: /var/www/html/sample/index.php<br />
Line: 292<br />
Function: require_once </p>
</div>
{"status":true,"message":""}"
This error does not occur in localhost.
In my case, i run the command in terminal
sudo a2enmod rewrite
After that i restarted Apache
systemctl restart apache2
In both cases you will need the admin password
This is a warning, that takes palce on your local too but probably you have disabled warning or you are using a different version of PHP. Since you are parsing json, it won't be able to parse it because the response is mixed with warning so it's not in pure json format.
sizeof
takes an array or an object that implements Countable. You can use this function after checking if the variable is an array or not by using this:
is_array($dataVariable)?sizeof($dataVariable):0
this will return zero if the variable is not an array. You can disable warning as well on production.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.