July 30th, 2010
When you have a set of string in an array or strings separated by comma (or any other character), you can use these two alternative. I prefer the second one
1
2
3
4
5
6
7
8
9
10
|
//code with explode
$list = explode(",",$astring);
foreach ($astring as $value) {
echo $value;
echo "<br />";
}
//code with str_replace
echo str_replace(",", "<br />", $astring); |
Tags: explode, php, str_replace
Posted in programming | No Comments »
July 28th, 2010
Easy way to forward using HTML files. Here’s the code
1
| <META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://www.yourdomain.com"> |
Tags: forwarder, html, redirect
Posted in programming | No Comments »
July 26th, 2010
Here is the link where you can download IP to country sql for database. Also come with some sample codes on how to use the data. Might be useful for your program
Tags: ip to country, ip2nation, mysql, resolve ip
Posted in database, programming | No Comments »
July 22nd, 2010
I’m looking for PHP encoding application to encrypt some of my PHP code. Reasons – to avoid it from being accidently altered and to avoid from people looking into the code (especially those with some important db and system config in it)
Here are some solutions for PHP encoding
- PHP Obfuscator – free (native windows, open source)
- zend guard
- ioncube (usd199)
- SourceGuardian (usd199)
- more..
Tags: php, php encoder, php encryption
Posted in programming | No Comments »
July 22nd, 2010
Worth to consider when building your website to make it search engine friendly.
Important SEO HTML tags
- title
- h1
- h2
- h3
- b
- strong
- img alt
- a href title and keyword in achor text
Use http://www.yourdomain.com/ (always with trailing slash at back)
.htaccess redirect to redirect http://yourdomain.com to http://www.yourdomain.com (site-wide)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) http://www.yourdomain.com/$1 [L,R=301]
Free sitemap at xml-sitemaps.com
Standard sitemap name/location – yourdomain.com/sitemap.xml
Robots.txt syntax
User-agent: *
Disallow: /privatefolder/
Disallow: /privatefile.html
Sitemap: http://www.yourdomain.com/sitemap.xml
Tags: search engine, seo
Posted in programming | No Comments »
July 15th, 2010
Found this function from bin-co. Haven’t tested the function but I think it might be useful for me in the future.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| //Get the result of the query as a CSV stream.
//http://www.bin-co.com/php/scripts/csv_import_export/
function CSVExport($query) {
$sql_csv = mysql_query($query) or die("Error: " . mysql_error()); //Replace this line with what is appropriate for your DB abstraction layer
header("Content-type:text/octect-stream");
header("Content-Disposition:attachment;filename=data.csv");
while($row = mysql_fetch_row($sql_csv)) {
print '"' . stripslashes(implode('","',$row)) . "\"\n";
}
exit;
}
//Import the contents of a CSV file after uploading it
//http://www.bin-co.com/php/scripts/csv_import_export/
//Aruguments : $table - The name of the table the data must be imported to
// $fields - An array of fields that will be used
// $csv_fieldname - The name of the CSV file field
function CSVImport($table, $fields, $csv_fieldname='csv') {
if(!$_FILES[$csv_fieldname]['name']) return;
$handle = fopen($_FILES[$csv_fieldname]['tmp_name'],'r');
if(!$handle) die('Cannot open uploaded file.');
$row_count = 0;
$sql_query = "INSERT INTO $table(". implode(',',$fields) .") VALUES(";
$rows = array();
//Read the file as csv
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row_count++;
foreach($data as $key=>$value) {
$data[$key] = "'" . addslashes($value) . "'";
}
$rows[] = implode(",",$data);
}
$sql_query .= implode("),(", $rows);
$sql_query .= ")";
fclose($handle);
if(count($rows)) { //If some recores were found,
//Replace these line with what is appropriate for your DB abstraction layer
mysql_query("TRUNCATE TABLE $table") or die("MySQL Error: " . mysql_error()); //Delete the existing records
mysql_query($sql_query) or die("MySQL Error: " . mysql_error()); // and insert the new ones.
print 'Successfully imported '.$row_count.' record(s)';
} else {
print 'Cannot import data - no records found.';
}
} |
Tags: csv, php
Posted in programming | No Comments »
June 29th, 2010
Suddenly two of my blogs could not be viewed. It was blank and another one display the “Warning: Visiting this site may harm your computer!” when browse with Google Chrome.
What I did to recover..
1. Remove the injected script in infected files (this can be checked in the error log file)
2. Login to my wordpress and export all content and save it on my PC
3. Download all my images in wp-content/uploads folder
4. Totally remove the wordpress
5. Do fresh installation with latest wordpress version available in Fantastico
6. Upgrade wordpress to latest version available with auto update feature
7. Make sure I don’t use “admin” as username for my blog and password at least 8 character long consists of aplhabet, number and special characters.
8. Install only neccessary and trusted plugins and themes. Immediately update plugins if new version available
9. Import all the files with import feature in tools
10. Copy back all the images to wp-content/uploads folder. Better check first to ensure no unwanted files in the folder.
Other than that..
1. Scan PC for virus and malware
Tags: blog, hack, inject, malware, virus, wordpress
Posted in technology | No Comments »
June 29th, 2010
Lots of new virus and malware nowadays. Keep your PC safe with these tools
AVG Free
Malwarebytes Anti-Malware
Another thing, try avoid using Internet Explorer. Google Chrome can better protect you from infected websites.
If you are using open source application like wordpress. Ensure that
- you are using the latest version
- your password is secure with at least 8 alphanumeric character with mix of special character and lower/upper case character
- you are using 3rd party plugins/themes from only reliable sources
- if possible try remove standard footer and header generated by the application (please read the terms first)
Other tips
- Don’t login to your web application in public and unsecure place or PC’s like in cyber cafe etc
- If you suspect your account was hacked, immediately change the password and inform your system admin or hosting/technical support
Tags: malware, virus
Posted in technology | No Comments »
June 27th, 2010
Easiest way to create a printer friendly page is by creating another css file. What I did is just removing the heading style.
CSS (save the CSS file as style-print.css)
#header is id for your header (div or table)
1
2
3
| #header {
display: none;
} |
In HTML add this line
1
| <link rel="stylesheet" href="style-print.css" type="text/css" media="print" /> |
Tags: css, html
Posted in programming | No Comments »
May 21st, 2010
If you are lazy to copy and paste the jquery file to your development folder for example when testing something simple, you can always use jquery hosted by google. To include it is very simple, you just include this script on the top and you’re done.
1
2
3
4
| <script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1.3");
</script> |
You are ready to use the jquery. Yahooo.. ups.. Goooooglee!!
Tags: AJAX, api, google, jquery
Posted in programming | No Comments »