Currently Viewing Posts Tagged script

How to connect DBF file and read data by PHP script

Afte last post, my php-fpm support the dbase database file now.  Here is an example php script.

$db = dbase_open('../db/clients.dbf',0);

if ($db){
	$record_numbers = dbase_numrecords($db);
	
	for ($i = 1; $i <= $record_numbers; $i++) {
		  $row = dbase_get_record_with_names($db, $i);
		  if ( strpos(trim($row['CLIENTNAME']), $clientname)  !== FALSE and $row['deleted'] != 1) {
			  	$clientid =  $row['CLIENTID']);
				
				echo 'Customer ID Number: ',$clientid,';
                 }
     }
}

0) The dbase file has two columns, one is CLIENTID, the other one is CLIENTNAME.

1) Open the dbase file, clients.dbf,  by relative path.

2) If the dbf file exists, get the total number of records.

3) Go through all records. If field CLIENTNAME is same as the variable, $clientname,  print client id.

Some changes on Timthumb script

What is Timthumb?

It is a small php script for cropping, zooming and resizing web images (jpg, png, gif).

 

Here is the official place to donwload the script. https://code.google.com/p/timthumb/

Even the developers said it is not supported any more, there are still a lot of sites or plugins of wordpress and joomla.

Here is some modification I did on one of the plugin of Joomla.

1) Change default quality of image file.

The original default is 90%, it is not good enough. Especially when testing the output on webpagetest.org. So reduce the default image quality to 70. Find the following in tb.php


if(! defined('DEFAULT_Q') )                                     define ('DEFAULT_Q', 70);                                                               // Default image quality. Allows overrid in timthumb-config.php

It can also be overrid in url paraments. Such as http://your.domain.name/tb.php?src=/images/abc.jpg&q=70

2) Add interlace or Make jpeg file progressive

It is good to make jpg file to be progressive. It is similar file size but make it display on the monitor faster.

This is actually a mod on the original timthumb script.

Add following in the defaults section of timthumb script.


if(! defined('JPEG_IS_PROGRESSIVE') )    define ('JPEG_IS_PROGRESSIVE', TRUE);

Then find following script


$imgType = 'jpg';
imagejpeg($canvas, $tempfile, $quality);

And add one line in the middle. Looks like below:


                        $imgType = 'jpg';
                        imageinterlace($canvas, JPEG_IS_PROGRESSIVE);
                        imagejpeg($canvas, $tempfile, $quality);

timthumb

 

 

How to add one string to all rows of one column

I have a MySQL database. There is one table has thousands rows of data. I need to add one string to every rows of one column.

It is a very popular scenario. Looks like in the middle of using one database, the developer need a new column with a default value in it.

Yes, he can setup a default value, but what about the existing data. The answer is shown below.

sample_table

+------+------+--------------+
| fieldA |  fieldB        |  fieldC | 
|  22    |  star          |     2   |
|  23    |  super         |     2   | 
|  24    |  savemore      |     1   |
|  25    |  justtolook    |     4   |
|  26    |  bestbook      |     4   |

I add this string to all rows of fieldB, just after the existing data.

The SQL script is used to do this job shown as below

Continue reading “How to add one string to all rows of one column”

Schedule Backup MySQL database and FTP offsite in Centos

I have a VPS powered by Centos 5.2.
There are some very important forum on it. I would like to backup it every day.
Now because HyperVM/LxAdmin – Backup Home, can not backup MySQL or not easy to get it. I have to write the shell script to do the backup job.
To use the FTP I need lftp tool.
The whole picture looks like below.
1) Dump all MySQL databases and compress them, save them in /home/usera/backup/mysql/
2) FTP them to Backup server of Dreamhost at /vps-backup/mysql/
3) Remove the backup files 4 days old.
You have to use your own account name and password.
usera is my sample user name. You can also use any other FTP server to save your offsite backups.
You make a file under /home/usera/mysql.backup.sh
Put the content below in it, save and make it executive.


Continue reading “Schedule Backup MySQL database and FTP offsite in Centos”

What can go wrong when including another file into your php file

It is very often to include another file as a part of your script.

require_once("/path"/to/file.php");

When do this kind of including, should be very careful on following parts.
1) The path to the script is wrong.
2) The path to the script is correct, but the script is in a forbidden directory.
3) The include file has a blank line or space before or after the code in the PHP script.
It is very easy to omit the space after the code.
4) The include file can be viewd by non-PHP methods.
5) You’re in include overload.
6) You are using unchecked variables as include filenames.
It may make your site unsafe in some situation.
The tips of including file are learned from “Wicked Cool PHP”

Making site stats accessible with htaccess

Dreamhost has a site stats facility included.
But sometimes it is not accessible because of the .htaccess file.
Say WordPress or some customized .htaccess file which will change the rewrite rule.
To make it works, add following code in top of the .htaccess file.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$[NC]
RewriteRule . - [L]

Windows Script Decoder

Now a lot of website owner find some malicious code hide in their webpages. Some are put by hacker.
The codes are also encoded. Webmaster can not remove the malicious code from the original html codes, they are all mixed.
Now, this tools is help you to decode it and find out.
The program name is Windows Script Decoder. The site is not available anymore.
You can download it from official site or download file here.
It is a command line tool. The usage is very simply.

scrdec18 [-cp codepage] [-urldec|-htmldec] [-verbose] [-dumb]

If you use following codepage try following number.
932 Japanese
936 Chinese (Simplified)
950 Chinese (Traditional)
949 Korean (Wansung)
1361 Korean (Johab)
This tool is so good. I used it yesterday. All smoothly.

Continue reading “Windows Script Decoder”

  • Archives