Archive

Archive for the ‘PHP Solutions’ Category

How to Determine Path to unzip With PHP

September 5th, 2010 No comments

Sometimes you need to know paths to some system software that needs to be executed with your script. For example, in order to unzip a file without installing or using any specific PHP classes or extensions, you need to know where the unzip binary is located.

The solution is very simple. The only restriction is that you should have rights to use exec() or system(). Though, I don’t think there is any reason to deal with the paths if you are not allowed to run system applications. Here is the code:


$var=exec ("which unzip");
echo $var;

What does this code do? It catches the output of system which command to a variable. Then you can use this variable for your purposes. Of course, you should verify the value of the variable before using it. You may also need to echo something, if unzip is not installed.

This technology can be applied to any other system binary you need to know the path of. $var=exec (“which sh”); will tell you the location of sh, if you need to run any shell scripts with your PHP script, and so on.

How to Create a db4 Database With PHP

April 20th, 2010 No comments

In order to create a blank db4 database with PHP script, all you need is to use this code:


$srcfile="/path/to/db4file";
$id=dba_open($srcfile, 'c', 'db4');
dba_close($id);
?>

Categories: PHP Solutions Tags:

Liberty Reserve Automation: 200Authentification Error

April 9th, 2010 No comments

This post is related to Liberty Reserve API. If you’re using it and have suddenly found that you cannot use in anymore, it is possible that you can face an authentication error. Even if your password, API name and secret word were not changed, you can get such a responce: 200Authentication error.

The solution is quite simple. If there were no changes made to user data, you should update your time. Yes, you should sync your server time to any time server. I can’t know the reason, but LR should ensure your time is correct before letting you use their API functionality. You can check Ntp Synchronisation setup or sync your time manually. Hope this saves you some time, as this feature is not documented.

Regular Expression to Validate URLs

February 10th, 2010 No comments

Here is a short regexp that is used to validate whether a user has entered correct URL address. Might be useful in any scripts dealing with user data.

I will show it as PHP code:

preg_match(‘/^(http:\/\/|https:\/\/)([^\.\/]+\.)*([a-zA-Z0-9])([a-zA-Z0-9-]*)\.([a-zA-Z]{2,4})(\/.*)?$/i’, $_POST['url']);

It will check whether url suits the pattern. May not be ideal, but it’s working. :)