Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Fix - CodeIgniter session not set with PHP 7.x


Today I had to do some updates to an old web app I made with CodeIgniter. The original app was made around 5 years back and there has been no changes to it until this one. All this time it was living in one of my old web servers with PHP 5.6 and had no issues at all. However, when I tried to setup this in my local machine (inside Vagrant, with PHP 7.x), I found some issues with the sessions. I noticed the sessions are not getting persisted between the redirects. 

 

After some research, I found out that the issue was actually with the PHP version. Luckily, I didn't have to change it to an old PHP version. There was an easy fix (somewhat surprising), and I got it working in no time. 

 

If you ever face this issue, all you got to do is: in your CI folder, open the CI/system/libraries/Session/Session.php file and look for a line which says:

 

ini_set('session.name', $params['cookie_name']);

and change it to

 

ini_set('session.id', $params['cookie_name']);

 

and that's it. Your app should start working fine :)

Fix Composer Memory Error - PHP Fatal error: Allowed memory size of xx bytes exhausted



I got this error while installing a Laravel package today and got it fixed so easily.

The exact error was this:

PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors. 


To fix this, you can either increase the memory limit for php, or ignore the memory limit for this command at the time you run this. I opted for the second method as I wanted to do this just one time.

Just run the same command as below:

php -d memory_limit=-1 <composer-bin-path> require <package-name>
Ex:
php -d memory_limit=-1 /usr/local/bin/composer require kreait/laravel-firebase

You can find the path for composer by using the following command. which composer
vagrant@homestead:~/$ which composer
/usr/local/bin/composer


Hope this will help someone.

GMAIL Mailbox names for IMAP connections?

GMAIL Mailbox names for IMAP connections

I worked on something interesting today. That was "creating a simple email client for Gmail", using the PHP's built-in IMAP library. I know there is an official PHP library provided by Google for that, and I have even wrote a blog post about it sometime back (explaining about a bug I found in it). But this time I wanted to do it with the Imap library instead.

So soon after finishing the Inbox, I started working on listing the "Sent Items". But to my suprise, I had a bit hard time finding the right mailbox name for the sent items. I assumed a few names like "Sent", "Sent Items", "Sent Messages", but none of them worked. So I turned to Google and did some search, and then I found this page on the Google Developers website.

https://developers.google.com/gmail/imap/

It explains everything about Gmail and the IMAP protocol, and how to actually use IMAP with Gmail. In the IMAP Extensions page, they have listed all the mailbox names and it was just a matter of using the right name.

Here's the list:


a004 LIST "" "*"
* LIST (\HasNoChildren) "/" "INBOX"
* LIST (\Noselect \HasChildren) "/" "[Gmail]"
* LIST (\HasNoChildren \All) "/" "[Gmail]/All Mail"
* LIST (\HasNoChildren \Drafts) "/" "[Gmail]/Drafts"
* LIST (\HasNoChildren \Important) "/" "[Gmail]/Important"
* LIST (\HasNoChildren \Sent) "/" "[Gmail]/Sent Mail"
* LIST (\HasNoChildren \Junk) "/" "[Gmail]/Spam"
* LIST (\HasNoChildren \Flagged) "/" "[Gmail]/Starred"
* LIST (\HasNoChildren \Trash) "/" "[Gmail]/Trash"


https://developers.google.com/gmail/imap/imap-extensions

The mailbox name should be the name you see inside the square brackets. ex: [Gmail]/Sent Mail

Here's how to use it:

$hostname = '{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail';

I thought I should post this in my blog, hoping that it would save someone else's time :) Please don't forget to leave a comment if it helped you. :)