Wednesday, October 10, 2012

Images of Shangri-La Pakistan

Shangrila Lake or Lower Kachura Lake is a part of the Shangrila resort located at a drive of about 20 minutes from Skardu (nearly 2,500 m or 8,200 feet) town.

It is a popular tourist destination, and has a unique restaurant that is built on the fuselage of an aircraft that had crashed nearby.

Shangrila was established in 1983 with the opening of the first Resort Hotel in Skardu, Baltistan. It was named "heaven on earth" because of its spectacular beauty,and breathtaking view and peaceful atmosphere. Shangrila Resort Hotel was founded by the late Brig.(Retd) Muhammad Aslam Khan, the first commander of the Northern Scouts of the Pakistan Army.

Shangrila was named after a book titled "Lost Horizon" by James Hilton. In the novel, the author narrates a tale in which an aeroplane crash landed near a riverbed, in the early 1920s. The surviving passengers came across some Buddhist monks from a nearby temple and sought their help. They were taken to a beautiful lamasery filled with a variety of fruits and flowers. The monks looked quite young, although they claimed to be hundreds of years old. The idyllic place was called Shangri-la, a Tibetan word meaning "Heaven on earth".









Saturday, September 29, 2012

javascript - window.open not working in IE - (RESOLVED)

Browser compatibility is an issue which each and every web-developer has to face. New window popup using javascript is the same kind of issue and javascript fuction window.open() has different functionality in defferent browsers like in firefox and chrome it works and in IE-8 etc sometimes it does'nt work.

I also faced this problem today and did R&D on it, and found a very simple solution to this. here is the solution of this problem.

In IE, you can't have spaces in your second variable (the new window's name).

Try:
 
window.open (address,'Ver_articulo', config=center);
 
Please post your comment and share this with others if you really like this post. 

Thursday, June 14, 2012

Email validation using PHP and REGULAR EXPRESSION

Form validation is a very important part of web programming. This is to avoid any mistakenly adding data in database. Validating emails can be done in many ways. But the most faster and efficient way to validate emails is using regular expression.

Here is the code of this validation in PHP.

if(isset($todo) and $todo=="test")
{  
    if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){  
      echo "<center>Invalid email</center>";  
    }else{  
     echo "<center>Valid Email</center>";
    }  
}   

Monday, May 28, 2012

How to delete DUPLICATE records from MYSQL table

Some times we need to delete duplicate rows from a table. Because there is no need for keeping duplicate records in same table. Deleting these duplicate records is very easy. It can be don using some simple SQL queries.

Here’s two easy ways to clean out that table quickly.

1) Use ALTER IGNORE on MySQL 5.1+
MySQL will allow you to create a unique index on a table with duplicate records with its IGNORE SQL extension:

 ALTER IGNORE TABLE 'SHIPMENTS' ADD UNIQUE INDEX (CART_ID, TRACKING_NUMBER)  

Duplicates will be deleted.

2) Recreate the table with GROUP BY

 execute 'CREATE TABLE shipments_deduped like shipments;'  
 execute 'INSERT shipments_deduped SELECT * FROM shipments GROUP BY cart_id, tracking_number;'  
 execute 'RENAME TABLE shipments TO shipments_with_dupes;'  
 execute 'RENAME TABLE shipments_deduped TO shipments;'  
 add_index :shipments, [:cart_id, :tracking_number], :unique => true  
 execute 'DROP TABLE shipments_with_dupes;'  

Recreating the table is much, much faster than trying to delete the records in the existing table and doesn’t lock the existing table, making your application downtime minimal.

Insurance

Friday, May 25, 2012

How to download and unzip a .ZIP file using php

Today I was working on a website which will be an affiliate member of another big company with already running a very good website ( i don't want to mention the name of that affiliate program because with this my idea is some how disclosed to the public and i don't want to do so :) ). In that affiliate program I have to download the feeds in .zip form and then importing that in my database. So I needed a script to automatically download, unzip and then import that data in my database. By using my experience and skills and also with the help of Google, I have successfully written a script for this purpose. In this post I am going to share the same,

First part of my script checks that php zip extension is loaded or not.
 if (!extension_loaded('zip')) {  
                dl('zip.so');  
           }  
After that, mention the path of download file and destination folder and rest of the script is as follows,
 $target_url = "http://www.example.com/test.zip";  
 $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';  
 $file_zip = "downloads/new.zip";  
 $file_txt = "downloads/".md5(time())."new.txt";  
 echo "<br>Starting<br>Target_url: $target_url";  
 echo "<br>Headers stripped out";  
 // make the cURL request to $target_url  
 $ch = curl_init();  
 $fp = fopen("$file_zip", "w");  
 curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);  
 curl_setopt($ch, CURLOPT_URL,$target_url);  
 curl_setopt($ch, CURLOPT_FAILONERROR, true);  
 curl_setopt($ch, CURLOPT_HEADER,0);  
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);  
 curl_setopt($ch, CURLOPT_AUTOREFERER, true);  
 curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);  
 curl_setopt($ch, CURLOPT_TIMEOUT, 10);  
 curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);  
 curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);   
 curl_setopt($ch, CURLOPT_FILE, $fp);  
 $page = curl_exec($ch);  
 if (!$page) {  
   echo "<br />cURL error number:" .curl_errno($ch);  
   echo "<br />cURL error:" . curl_error($ch);  
   exit;  
 }  
 curl_close($ch);  
 echo "<br>Downloaded file: $target_url";  
 echo "<br>Saved as file: $file_zip";  
 echo "<br>About to unzip ...";  
 // Un zip the file  
 $zip = new ZipArchive;  
   if (! $zip) {  
     echo "<br>Could not make ZipArchive object.";  
     exit;  
   }  
   if($zip->open("$file_zip") != "true") {  
       echo "<br>Could not open $file_zip";  
         }  
   $zip->extractTo("$file_txt");  
   $zip->close();  
 echo "<br>Unzipped file to: $file_txt<br><br>";  
If you like this script, so please post your comments and feedback. Your good feedback is the main desire of me to continue writing useful posts for my blog reader. Thanks