CodeIgniter Session Error – Operation not Permitted

On some hostings you can receive this error.

A PHP Error was encountered

Severity: Warning

Message: unlink(/tmp/ci_session0189a7f1c86eb18fb70afcfedc2d5040e9c23146): Operation not permitted

Filename: drivers/Session_files_driver.php

To fix this go to application > config > config.php and edit this line:

$config['sess_save_path'] =  BASEPATH . 'cache/';

Laravel first steps

Hello, this article is for beginners and will show basic functions.

Installation of Laravel

To begin with instalation we need composer. In console write the following.

composer create-project --prefer-dist laravel/laravel NameOfTheProject

What is artisan

Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.

Continue reading “Laravel first steps” »

Laravel on shared hosting

I will show you not the fastest but easiest way to move Laravel project to shared hosting. You need to be sure that you are using PHP version >= 5.6.4.

First step

First connect to your FTP and create folder outside “public_html”. You can use any name but in this example I will use (“Laravel”) for the name of this folder.

Move everything except “public” folder from your Laravel project to your newly created folder on shared hosting. It will take some time!

In “public_html” folder you need to move files from “public” folder in your Laravel project.

Open index.php file and change the paths to autoload.php and app.php files. They should point to files in the Laravel folder.
Continue reading “Laravel on shared hosting” »

Codeigniter 3 – Fast setup

Download and extract codeigniter. In main folder create another folder named assets. There will be additional files for css, js and more.

Setup configuration files. Go to application/config:
– in autoload.php

$autoload['libraries'] = array('database','session');
$autoload['helper'] = array('url','form');

– in config.php

$config['base_url'] = 'http://www.example.com/';
$config['index_page'] = '';
$config['encryption_key'] = 'someEncryptionKey';
$config['sess_save_path'] = sys_get_temp_dir(); //Fix problems with session

– in database.php

'username' => 'root',
'password' => 'rootPassword',
'database' => 'DatabaseName',

– in routes.php

$route['default_controller'] = 'Main_controller';

Step 2 Create Main_controller file in application/controllers
Easiest way is to copy and rename Welcome.php

Step 3 Create .htaccess file in main folder. This is a must for routing!

RewriteEngine On

RewriteCond %{HTTP_HOST} ^my-domain.com [NC]
RewriteRule ^(.*)$ http://www.my-domain.com/$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ http://www.my-domain.com/$2 [R=301,L]
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Multilanguage CodeIgniter 3.0

In this tutorial we will implement multilanguage to CodeIgniter.

Site Default Language
Open the application/config/config.php file and specify the site’s default language.

$config['language']  = 'bulgarian';  //Language you want to be default

Language Files

The language files must be named with _lang suffix. For example, if you want to create a file containing site’s message translation then the file name might be message_lang.php.

Insert those files into the application/language/ directory with separate sub-directories for each language (for example, english, bulgarian, etc.).
Continue reading “Multilanguage CodeIgniter 3.0” »

Pagination example

PHP and HTML

  • «
  • $last){$top=$last;} if($x<=0){$bottom+=1;$top+=1;} } for($i=$bottom;$i<=$top;$i++){ ?>
  • ">
  • »

jQuery

$(document).on("click",".pbutton",function() {
		var selected = this.text; //Selected page
		if(selected=="«"){selected = 1;} //first rows
		if(selected=="»"){selected = $(".last_page").attr("id");} //last rows
		
		$.ajax({
		  url:'admin.php',
		  type:'POST',
		  data:{ 
			command:"show_regular_quotation", //name of var: value of var  
			selected:selected
		  }  
		 }).done(function(data){
			$(".content").html(data);
		});		
	});

The code is perfectly compatible with bootstrap.

Currency convertor with PHP

function currency_convert($amount, $from, $to){
	$result = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from&to=$to");
	$result = explode("",$result);
	$result = explode("",$result[1]);  
	$converted_amount = preg_replace("/[^0-9\.]/", null, $result[0]);
	echo $converted_amount;
}

currency_convert(1,'gbp','usd');