Tag Archives: php.ini

Install Zend Framework on Shared hosting server

If your site is hosted on Shared Server and you want to use Zend library on your project.

 

For Dedicated server, you have full root access and can have remote or full putty access of your server, you can install/uninstall any library as well as software in the server.
The same will be done by Server Guy on your request.

 

But, in this case “Shared hosting”, you should handle these either by using .htaccess file or by overriding the php.ini file, let see how you can do this.

 

If you need to install Zend framework what you should do is.

 

1. Check the document root path of your server.Use phpinfo(); php function for check.

<?php
echo phpinfo();
?>

The below is the sreengrab of my local system, the path will be different for your server.

XAMPP_Document_Root_PATH_PHPinfo

 

 

2. Upload Zend library into your hosting server (path : root/library/Zend)

 

3. Create or update your php5.ini (If you are using php5, use php5.ini file) or php.ini file.

put this line, (If you already have, add this line end of the current set, connected with ‘:’)

include_path = [DOCUMENT_ROOT]/Zend Libraray Path

ex) include_path = /home/scriptarticle/public_html/library

 

It’s Done !!

Now test whether the zend installed well or not, let’s echo the Zend frame work version.

 

<?php
require_once 'Zend/Version.php';
echo 'Zend Framework Version : ' . Zend_Version::VERSION;
?>

 

If you see your Zend version, that means your Zend framework has been installed successfully!

 

Save

PHP short_open_tag = On should not be used

After a fresh installation you could find that PHP short_open_tag disabled by default in php.ini file.

 

You can check by using phpinfo() PHP function.

Under PHP Core setting you can find as below

 

Directive Local Value Master Value
short_open_tag Off Off

 

If “short_open_tag” is found off in your php.ini file then you cannot use short form (<? ?>) of PHP’s open tag and you must use long form of PHP tags (<?php ?>) instead, otherwise any PHP code inside these tags will not be parsed as PHP.

 

Drawback of PHP short_open_tag if you have enabled.

 

1) Setting this value to off allows for easier use alongside XML by providing the ability to use <?xml ?> inline without having to print it with PHP echo ‘<?xml version=”1.0″?>’; ?>.

 

With the wide spread use of XML(SOAP, XMLRPC, REST-XML) and use of these tags by other languages, the server can become easily confused and end up parsing the wrong code in the wrong context. But because this short cut has been a feature for such a long time, it’s currently still supported for backwards compatibility, but it’s recommend you don’t use them.

 

2) All the standard library use <?php ?>, full php tags so we can say it’s a standard, if you are open source script (distributable or portable script) writer or have PHP open sources community member then it’s always recommended to use full tag instead of short_tag as by default PHP have it disabled in php.ini settings.

 

3) Due to security reasons in some extent it’s advised to not to use short_open_tag.

 

If you still want to use short_open_tag or if you have just entered in a large application that is previously build by any other developer and he have used short_tags in many places, but your you php setting is was disabled then you should enabled short_open_tag, let me tell how you should do this quickly.

 

1) Open you root’s .htaccess file and add the following in that

php_flag short_open_tag on

or

php_value short_open_tag 1

 

2) If you php.ini access and can update any php directive and setting then open php.ini file and change
short_open_tag = Off to short_open_tag = On

It’s always advised to start Apache services after any changes in php.ini settings.

 

3)

 ini_set( "short_open_tag", 1 ); 

will not work, if you are trying to do as it (short_open_tag) is marked as PHP_INI_PERDIR in PHP < 5.3.0, which means you can’t change it with ini_set(). You can check this by below link.

 

Description of core php.ini directives

 

 

Solved: PHP move_uploaded_file and copy function both is not uploading the file in destination directory

Fixed: PHP move_uploaded_file() and copy() function is not uploading the file

In the programming field we usually need to upload the files in the folders.

In PHP, we have 2 functions for the purpose.

1st is move_uploaded_file()

2nd one is copy().

 

I think you know well, what the difference between these two copy() vs move_uploaded_file().

Well, if you not aware about the difference between the above 2 PHP functions that is used for file uploading.
Click to view the difference between PHP copy() and PHP move_uploaded_file() function.

 

But this is not my prupose for wrting this post. I want to aware you that sometimes the file uploaded error is something different.
First of all whenever you upload a file you just need to check weather you have used encryption type enctype=”multipart/form-data” and have to use POST method.

 

GET method can’t upload file in any case.
Cool, you have used that then first of all check weather the file has been passed by form and have uploaded to the temp directory.
Basically this is the functionality of file uploading, first during the form post action file uploaded to the temp directory and then we have to move or copy that file in our desired folder or directory.

 

How can you check the temp directory, in which file is going to upload, you can check the same using phpinfo().

upload-temp-directory

You can also change the same (default temp directory) that can be seen in the php.ini file.

If you uploaded a file, but file is not uploaded, first check whether the file ha been uploaded in temp directory or not.
If there has been some error occurred, you can check by print_r array of $_FILES variable.

 

$_FILES

If you get error that means files is not uploaded in temp directory.
It may have 2 reasons, whether the directory no exists or the directory hasn’t proper permission.

 

You can get rid by 2 solutions.

1) Change the path of temp directory in php.ini
2) Check the permission and folder existence.

 

I think, you will better fix the issue related to file upload.

Better Coding, Happy Coding!!

Save

How to install ioncube loader in xampp

1. Find your PHP version using phpinfo() function. You should need to know the version when you download the ionCube loaders.

 

x86/ppc/sparc packages are for 32 bit systems;
x86-64/ppc64 packages are for 64 bit systems.

 

The Windows non-TS Loaders are for use on a Windows system where a phpinfo() page shows that PHP is built with thread safety disabled.

 

2. Download ionCube loader from: http://www.ionCube.com/loaders.php

Download this version: Windows VC9 (x86) – Windows Installer

 

3. Install ionCube loader to XAMPP at: D:\xampp\htdocs\ioncube

 

4. Open php.ini with in text editor.

The file is located at D:\xampp\apache\bin\ or D:\xampp\php\.
Add the following line before any other zend_extension statement.

zend_extension = “D:\xampp\htdocs\ioncube\ioncube_loader_win_5.3.dll”

And Save this file.

 

5. Run (or restart) XAMPP, and open the following link http://localhost/ioncube/loader-wizard.php

 

6. For security reasons we advise that you remove this Wizard script (loader-wizard.php) from your server now that the ionCube Loader is installed.
Remove this! http://localhost/ioncube/loader-wizard.php

Just done!

 

Note: I prefer to put the “ioncube” folder in “D:\xampp\php” instead of htdocs, if you do so, you should also update the path in php.ini file.

How to fix ‘Function ereg() is deprecated’ in PHP 5.3.x?

If you upgraded your PHP version to PHP 5.3.x, you will get few warnings or deprecated function messages like function ereg() is deprecated in php 5.3.x. You can find the full list of functions that are deprecated by following URL Deprecated features in PHP 5.3.x

ereg family functions are deprecated in PHP 5.3.0 or later,as these were slower and felt less familiar than the alternative Perl-compatible preg family.

To migrate ereg()

ereg('\.([^\.]*$)', $file_name, $extension);

becomes

preg_match('/\.([^\.]*$)/', $file_name, $extension);

Notice that wrapped the pattern (\.([^\.]*$)) around / /, which are RegExp delimiters.
If you find yourself escaping / too much (for an URL for example), you might want to use the # delimiter instead.

To migrate ereg_replace()

$file_name = ereg_replace('[^A-Za-z0-9_]', '', $file_name);

becomes

 
 // preg_replace($pattern, $replacement, $string);
 $file_name = preg_replace('/[^A-Za-z0-9_]/', '', $file_name); 

 

If you are using eregi functions (which are the case-insensitive version of ereg), you’ll notice there’re no equivalent pregi functions.
This is because this functionality is handled by RegExp modifiers.

To make the pattern match characters in a case-insensitive way, append i after the delimiter.

eregi('\.([^\.]*$)', $file_name, $extension);

becomes

preg_match('/\.([^\.]*$)/i', $file_name, $extension);

get_magic_quotes_gpc PHP Function & data filtering

get_magic_quotes_gpc()

There is a PHP feature or function called as magic quotes that was created to help protect newbie programmers from writing bad form processing code. Magic quotes will automatically escape risky form data that might be used for SQL Injection with a backslash \.

 

The characters escaped by PHP magic quotes includes : quote ‘, double quote “, backslash \ and NULL characters.

 

You need to check to see if you have magic quotes enabled on you server. The get_magic_quotes_gpc function will return a 0 (off) or a 1 (on).

 

<?php
/*  function to insert the data in database safely */
function filter($str)
{
	$str = trim($str);
	if (!get_magic_quotes_gpc()) {
		return addslashes($str);
	} else {
		return $str;
	}
}
?>

Get back data from database and remove the filter (to remove the slashes).

 

<?php
/*  function to remove the slashes that was the added during the data insertion in database */
function remove_filter($str)
{
	return stripcslashes($str);
}
?>

In the later version of PHP 5.4 or later it will always returns FALSE because the magic quotes feature was removed.

 

We can get_magic_quotes_gpc will deprecated in later versions of PHP.