Thursday, April 26, 2012

PHP, server infomation and unique identifier



To print out server information in PHP:
<?php
 print_r($_SERVER)
?>
I tested a PHP code in my localhost:8083,  When I used $_SERVER['SERVER_NAME'], the result is
localhost.  The variable $_SERVER['HTTP_HOST'] should be used to represent localhost:8083.

Sometimes we need to use  prefixed unique identifiers as a primary key. in PHP.  PHP function uniqid() can be used, which produces a prefixed unique identifier based on the current time in microseconds.
example:
uniqid('g');   a unique identified with prefix g based on time.
uniqid('u');   a unique identified with prefix u based on time.
 

PHP, check if the checkbox is checked



Suppose we have a check box array demo[]
<input type="checkbox" name="demo[]" value="1" />A
<input type="checkbox" name="demo[]" value="2" />B
<input type="checkbox" name="demo[]" value="3" />C

To check if any checkbox is checked
   if(!isset($_POST['demo'])){
    echo "You need to check the checkboxs";
   }

 To access the checkbox values using:
$_POST['demo'][0],  $_POST['demo'][1], $_POST['demo'][2]

To make a default checked, for example in the second checkbox
 <input type="checkbox" name="demo[]" value="2" checked />

Result for demo:
A B C

Sunday, April 22, 2012

Using Google to search only your site



You may not want to  spend  time  to design a search engine to search over your website.  Yes, you can use Google to search only over your site. For example, I want to search "Canada Economy 2012" only in tsx.com. I just need to input "site:tsx.com, Canadian economy 2012" in Google search. All results are from tsx.com.  Similarly, if you used " site:money.cnn.com", then all results are from money.cnn.com.

Below is the example to search the content in  the website checked (only one website allowed to be checked)
Source code:
 <form action="http://www.google.com/search" method="get" target="_blank">
<input maxlength="255" name="q" size="25" type="text" value="" />
<input type="submit" value="Google Search" /><br />
<input name="sitesearch" type="checkbox" value="video.yahoo.com" />video.yahoo.com <br />
<input name="sitesearch" type="checkbox" value="www.youtube.com" /> www.youtube.com <br />
<input name="sitesearch" type="checkbox" value="www.dailymotion.com" />www.dailymotion.com <br />
<input name="sitesearch" type="checkbox" value="www.truveo.com" /> www.truveo.com </form>

Result:


video.yahoo.com
www.youtube.com
www.dailymotion.com
www.truveo.com

Collection of English Video sites



Below is my collection of English Video sites:
http://video.yahoo.com
http://www.youtube.com
http://photobucket.com/recent/videos
http://www.dailymotion.com
http://is.rediff.com
http://vision.rambler.ru
http://www.yourfilehost.com
http://www.tinypic.com
http://cnettv.cnet.com
http://www.ning.com
http://www.veoh.com
http://www.justin.tv
http://www.break.com
http://video.google.com
http://www.hulu.com
http://www.archive.org/details/movies
http://www.truveo.com
http://www.webshots.com
http://www.crunchyroll.com
http://www.gametrailers.com
http://www.tu.tv
http://www.esnips.com
http://www.flurl.com
http://us.dada.net/vide
http://www.pandora.tv
http://stage6.divx.com
http://www.buzznet.com
http://www.collegehumor.com
http://www.vimeo.com
http://www.ustream.tv
http://youtomb.mit.edu
http://www.ebaumsworld.com
http://www.livevideo.com
http://www.liveleak.com
http://vbox7.com
http://www.sevenload.com
http://www.funnyordie.com
http://www.Heavy.com
http://blip.tv
http://www.current.com/
http://www.dalealplay.com
http://www.maniatv.com
http://www.mogulus.com
http://www.blogtv.com
http://www.pawky.com
http://www.activistvideo.org
http://www.wtfhumor.com   
http://www.motorsportstube.com
http://www.filecow.com
http://www.clonevideos.com
http://www.entertane.com
http://vids.myspace.com
http://www.joost.com

Mirror my WordPress website



I have a free host WordPress website:
 http://www.jiansenlu.zoka.cc/wordpress/
After I received several emails  to remind me to update to a premium account,
I decided to backup or mirror my WordPress to another free host website.
I choose
 http://www.000webhost.com/
My WordPress mirror site:
http://jiansenlu.comze.com/wordpress/

To copy and restore WordPress from one site and another is as follows:
1) Copy the wordpress directory to another site.
2)  in wordpress/wp_config.php, change
define('DB_NAME', 'zokac_6523699_wordpress');

/** MySQL database username */
define('DB_USER', 'zokac_6523699');

/** MySQL database password */
define('DB_PASSWORD', 'password');

/** MySQL hostname */
define('DB_HOST', 'sql106.zoka.cc:3306');

to new database hostname, database name, database username and password.
3) run wordpress/wp_config.php

4) login your WordPress admin account, select Export under Tools in left menu in old website,
save file as xml file.

5) login new WordPress website as admin,  select Import under Tools in left menu. You can select new theme or use original theme.

Done

Friday, April 20, 2012

Remove Babylon search in Windows 7


 I did not install Babylon program. But Babylon search quietly replace my Google search when I am not aware. Previously, when I type ads in my Firefox  toolbar, the webpage is redirected to the cache of my Google Adsense.  After the Babylon toolbar is installed, the webpage is redirected to the Babylon search engine.

 I checked and found that Babylon is an advanced online/offline translation program. But It is too aggressive and I also do not need it. I decide to remove it from my computer.

To remove Babylon search is quite easy in Windows, uninstall it as a regular program.

  Go to the Start Menu. Select Control Panel,  go to program ->Program and features ->uninstall a program,  Search for Babylon in the list, right click mouse and select uninstall.

You may also need to remove it from Firefox.
  go into firefox, click on "tools", and look for "add-ons."  look for  Babylon Toolbar, and select disable or remove.  Restart Firefox.





Thursday, April 19, 2012

Monitor your Gmail login activity



If you worry about some other people may log in your Gmail account and spy  your email, you can check your Gmail login activity.  After you sign in your Gmail account, at the right bottom of your Gmail, you can find:
"Last account activity: 1 hour ago
Details"
Click the link in detail, you can  see|:
Activity on this account
This feature provides information about the last activity on this mail account and any concurrent activity. Learn more
This account does not seem to be open in any other location. However, there may be sessions that have not been signed out.

Recent activity:
Access Type [ ? ]
(Browser, mobile, POP3, etc.)
Location (IP address) [ ? ] Date/Time
(Displayed in your time zone)

Check if any abnormal activity. 


Wednesday, April 18, 2012

PHP, extract information from Google calendar



We can use Google  Data APIs to extract Google calendar data and other Google application.
The Google Data APIs are a set of web services for read/write access to applications hosted by Google. Zend_Gdata provides PHP 5 client interfaces for the Google Data APIs.

Download Zend Gdata package from:
 http://framework.zend.com/download/gdata

 After unzip the data and extract the data, the directory like this:
ZendGdata-1.11.11
I copy the  ZendGdata-1.11.11/library/Zend to the Zend directory under  my web root directory.
Below is the PHP test code to extract  public Google calendar event title and time in 8 days for Gmail account test@gmail.com
 <?php
 //ini_set('display_errors', 1);
//error_reporting(E_ALL);

require_once($_SERVER['DOCUMENT_ROOT'].'/Zend/Loader.php');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_HttpClient');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
$service = new Zend_Gdata_Calendar();
$query = $service->newEventQuery();

$query->setUser('test@gmail.com');

$query->setVisibility('public');
$query->setProjection('full');
$query->setStartMin(date('Y-n-j'));
$query->setStartMax(date('Y-n-j', time() + (60*60 *24*8)));
$query->setOrderby('starttime');

try { $eventFeed = $service->getCalendarEventFeed($query); }
catch (Zend_Gdata_App_Exception $e) { return; }
echo "<ul>\n";
  foreach ($eventFeed as $event) {
    echo "\t<li>" . $event->title->text .  " \n";
    echo "\t\t<ul>\n";
    foreach ($event->when as $when) {
      echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n";
    }
    echo "\t\t</ul>\n";
    echo "\t</li>\n";
  }
  echo "</ul>\n";

?>
To access the private calendar with authentication: (replace test@gmail.com and test_password with true Gmail user name and password)
<?php
 ini_set('display_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set('America/Vancouver');
require_once($_SERVER['DOCUMENT_ROOT'].'/Zend/Loader.php');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_HttpClient');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
    $user = "test@gmail.com";
    $pass = "test_password ";
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
    $service = new Zend_Gdata_Calendar($client);

$query = $service->newEventQuery();
$query->setVisibility('private');
$query->setProjection('full');
$query->setStartMin(date('Y-n-j'));
$query->setStartMax(date('Y-n-j', time() + (60*60 *24*8)));
$query->setOrderby('starttime');

try { $eventFeed = $service->getCalendarEventFeed($query); }
catch (Zend_Gdata_App_Exception $e) { return; }
echo "<ul>\n";
  foreach ($eventFeed as $event) {
    echo "\t<li>" . $event->title->text .  " \n";
    echo "\t\t<ul>\n";
    foreach ($event->when as $when) {
      echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n";
    }
    echo "\t\t</ul>\n";
    echo "\t</li>\n";
  }
  echo "</ul>\n";


?>

To insert event in your Google calendar:
<?php
 ini_set('display_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set('America/Vancouver');
require_once($_SERVER['DOCUMENT_ROOT'].'/Zend/Loader.php');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_HttpClient');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
    $user = "test@gmail.com";
    $pass = "test_password";
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
    $service = new Zend_Gdata_Calendar($client);

$query = $service->newEventQuery();


$query->setVisibility('private');
$query->setProjection('full');
$query->setStartMin(date('Y-n-j'));
$query->setStartMax(date('Y-n-j', time() + (60*60 *24*8)));
$query->setOrderby('starttime');

try { $eventFeed = $service->getCalendarEventFeed($query); }
catch (Zend_Gdata_App_Exception $e) { return; }
echo "<ul>\n";
  foreach ($eventFeed as $event) {
    echo "\t<li>" . $event->title->text .  " \n";
    echo "\t\t<ul>\n";
    foreach ($event->when as $when) {
      echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n";
    }
    echo "\t\t</ul>\n";
    echo "\t</li>\n";
  }
  echo "</ul>\n";

$newEvent = $service->newEventEntry();
$title="Jiansen Test";
$newEvent->title = $service->newTitle($title);
$where ="cesei";
$newEvent->where = array($service->newWhere($where));
$description="This is a test";
$newEvent->content = $service->newContent("$description");
$startDate="2012-04-19";
$endDate="2012-04-19";
$startTime = '10:00';
$endTime = '11:00';
$tzOffset = '-08';
$when = $service->newWhen();
$when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
$when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
$newEvent->when = array($when);
$who = $service->newwho();
$who->setEmail('test@gmail.com');

$SendEventNotifications = new Zend_Gdata_Calendar_Extension_SendEventNotifications();
 $SendEventNotifications->setValue(true);
$newEvent->SendEventNotifications = $SendEventNotifications;
    

       
$newEvent->setWho(array($who));
// Upload the event to the calendar server
// A copy of the event as it is recorded on the server is returned
    // This event will occur all day every Friday starting from 9th July 2010 until 8th Dec 2015
    /*
    $recurrence = "DTSTART;VALUE=DATE:20100709\r\n" .
            "DTEND;VALUE=DATE:20100710\r\n" .
            "RRULE:FREQ=WEEKLY;BYDAY=Fr;UNTIL=20151208\r\n";
    
    $newEvent->recurrence = $service->newRecurrence($recurrence);
*/

$createdEvent = $service->insertEvent($newEvent);


?>

Friday, April 13, 2012

Contact me form using Google document


You can use Google document to create a "contact me" form. You also  have a lot of choices for your form background. After you created a form, you can embed in your website using iframe.
(replace your form url to your Google form address.
 <iframe src="your form url" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
 When any user fills the form, you can see the information in your Google document. You can go to Tools->notification rule in your Google document to set: when a user submit a form, you receive an email notification.

Below is my form example.

Tuesday, April 10, 2012

Jquery video tutorial



I quite like derekbanas's Jquery video tutorial. The video quality is good and teaching method is great. Below is the Jquery video tutorial from part 1 to part 8.

 Part 1:The techniques to implement a dynamic site using Asynchronous JavaScript and XML (AJAX).

 Part 2: How to add multiple CSS styles with JQuery : What are all of the JQuery selection options : Assign events with JQuery : Explain JQuery animations : Change element values with JQuery

 Part 3: JQuery Event Handling : Bind Events to an Element : Change Content Dynamically : Track Mouse Movement : Monitor Keyboard Presses : Track Every Event

Part 4: JQuery provides numerous ways to add elements and precise ways to delete others: before(), insertBefore(), prependTo(), appendTo(), append(), insertAfter(), after() and remove().

Part 5: JQuery UI library, ways to animate elements using JQuery: hide, show, toggle, fadeOut, fadeTo, slideUp, slideDown, animate and effect.

 Part 6: how to download the code needed to use JQuery widgets, how to create Accordions in 2 ways and how to create an image slide show.

Part 7:Learn Ajax and how to retrieve plain text and XML, to access PHP code that can access databases, or any other type of information.

Part 8: how to create a really nice JQuery Lightbox and a tab interface that is: draggable, resizeable, and sortable.

Click Part 1 to part 8 to display in same window.

Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part 7 Part 8

Monday, April 9, 2012

Useful Google Gadget Demo

 

 There are thousands of Google gadgets. A lot of them are out-of-date and low quality. But nobody clean these. Of course, some of them are very useful. 

In Google sites, you can directly click insert and more gadgets in edit mode.
In other websites, you can Google gadget codes via:

http://www.google.com/ig/directory?synd=open&hl=en&gl=en&cat=all

 To test these Google  gadgets is quite time consuming.  I tested some of them:
  iframe,   embed gadget ,Text Box , World webcam , Fish gadget ,  Chessing game , Minesweeper game  Google translate gadget ,   Unit Converter ,  Google Dual-Mode Calculator , World Weather,
 embed video Google Map Search
More to come.

I put these " Useful Google Gadget Demo" in my Google site:
 https://sites.google.com/site/usefulgadgetdemo/

Sunday, April 8, 2012

Using Miscrosoft Office Starter for Office application



I have an office in my old computer, which is $100.  When I bought a new computer, I can not migrate it to the new computer.

The good news is that Microsoft offers free Microsoft   Office starter with new PCs.
Microsoft Office starter offers  limited-functionality versions of Word and Excel and includes advertising. Microsoft Office starter   does not include PowerPoint or Outlook. It only comes with new PCs with preloaded Office 2010 suites.

As I only use MS Words to view Words documents,  MS Office starter is fine for me. For PowerPoint, you can download free PowerPoint viewer from:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13

If you do not have option to install Microsoft Office Starter, you can  download Word viewer for free from:
 http://www.microsoft.com/download/en/details.aspx?id=4

If you want to create PowerPoint, but you do not want to buy MS Office, you can download Open Office for free instead from:
 http://www.openoffice.org/download/other.html

Saturday, April 7, 2012

System requirement for watch online videos



To watch  online video, such as YouTube, you need a sound card at least 16-bit, and video card at least 64MB of video memory. Some old computers do not have video card built-in, which will cause videos very slow, sometimes on and off.  I recently visited Best-Buy store, I saw one computer with video card and another one without sound card, the price only 20$ difference. It is better to ask if sound card is built -in when you buy a computer.

Processor 1GB and RAM 256 MB at least, which is no problem for recent computers.  Broad Band connection at least  500+ Kbps.  You also need to install latest Adobe Flash Player for plug-in and update your browser often for best performance.

Friday, April 6, 2012

Corning Glass new technology will reshape our future



Corning glass is the company  for the future of glass technologies.
Corning Video  “A Day Made of Glass.” gave a glimpse into how glass, partnered with companion technologies, will help shape our everyday lives. Cool, touch-friendly glass with Internet technology in home, hospital and workplace will reshape our world.  Think about all your windows at home are touch-screen.  Current touch-screen devices are not transparent.
Video: A Day Made of Glass 2: Same Day. Expanded Corning Vision.


Thursday, April 5, 2012

Free host forum is not reliable



I have a forum last year:
http://jiansenlu.my-forum.net/
which is a free forum hosted at:
http://my-forum.net/
The server is down  for a few months this year. I heard it is for sale.
Now the server is coming back. But no content inside.
I hope it will be recovered in near future.
This reminds me always to have a backup of  my website and on-line files.  I recommend to use WinHTTrack
 http://www.httrack.com/

I also have some websites hosted in some free hosts. The companies keep reminding me to upgrade to  a premium account.  After using so many free web servers, I found Google is the best. But  still having a backup is a best choice in case your account is hacked.

HTML, create a button to redirect a link



You may need to create   a button redirect to another page.
Method 1: (When you click search button, redirect to Google website)
 <input type="button"  VALUE="Search" onclick="window.location = 'http://www.google.com';"> 
Result:

Method 2, using form
 <FORM METHOD="LINK" ACTION="http://www.google.com">
<INPUT TYPE="submit" VALUE="Search">
</FORM>


More application:
You can add a edit button  in each of your webpage, for administrator, edit button will showup.
When the edit button is clicked, the page will be redirected to a editable page.
Using PHP
     <?php $redirect_url=$_SERVER['PHP_SELF'].'?edit=1'; ?>
<input type="button"  VALUE="Edit1" onclick="window.location ='<?php  echo $redirect_url;?>';">


Tuesday, April 3, 2012

Create CSS horizontal and vertical menus




To design horizontal and vertical menu, we mainly customize   <ul> and <li> elements using CSS.
1) To create a horizontal bar, we can use inline  list items.
 default li style in HTML4, which creates items in vertical
li { display: list-item }
 
See  Appendix D. Default style sheet for HTML 4:
 http://www.w3.org/TR/CSS21/sample.html
 
 To list items in horizontal, we use
<style type="text/css">
li
{
display:inline;
}
</style>
In a:link,a:visited, using padding:6px; to build a block for each item
 and set the block color using background-color:#98bf21; To remove the underline of the link using text-decoration:none;
a:link,a:visited
{
background-color:#98bf21;
padding:6px;
text-decoration:none;
}

2) To create a horizontal bar, we can use  floating list items, which is different from the inline style
For  floating list items
 li
{
float:left;
}

In a:link,a:visited, using display:block; width:60px; to build a block for each item
and set background color background-color:#dddddd; as the example below:
a:link,a:visited
{
display:block;
width:60px;
background-color:#dddddd;
}

3) To create a vertical menu, we do not need to define li as its default is vertical
To remove list style, using:
ul
{
list-style-type:none;
}
To make each bloack has equal width, we define an id:
#menuh
        {
        font-size: small;
        font-family: arial, helvetica, sans-serif;
        width:20%;
        float:left;
        margin:2em;
        margin-top: 1em;
        }
The final code is:
<html>
<head>
<style type="text/css">
#menuh
        {
        font-size: small;
        font-family: arial, helvetica, sans-serif;
        width:20%;
        float:left;
        margin:2em;
        margin-top: 1em;
        }
#menuh ul
{
list-style-type:none;
margin:0;
padding:0;
}

#menuh a
        {
        text-align: center;
        display:block;
        border: 1px solid #555;
        white-space:nowrap;
        margin:0;
        padding: 0.3em;
        }

#menuh a:link, #menuh a:visited, #menuh a:active        /* menu at rest */
        {
        color: white;
        background-color: royalblue;
        text-decoration:none;
        }

#menuh a:hover                                          /* menu on mouse-over  */
        {
        color: white;
        background-color: cornflowerblue;
        text-decoration:none;
        }
</style>
</head>
<body>
<div id="menuh">
<ul >
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</div>
</body>
</html>
Result:
You can get the CSS or HTML  codes  of  horizontal and vertical menus from:
 http://www.mycssmenu.com/
To get the menu code:
1) Go to  http://www.mycssmenu.com/
2) Choose the menu  you like.
3) Click customize,  a nice editor with menu will show up. You can edit the menu
4) Click CSS or HTML and get the code.

Although there are too many ads in that website, but it is quite handy for the menu codes.

More reference:
 http://www.w3schools.com/css/css_navbar.asp

Free flash file hosting



 Swfcabin provides speedy  effective, free swf hosting. You even do not need to  create a login name and password. To publish your flash file on-line:
1) Go to:
http://swfcabin.com/
2) Upload the flash file from you local computer, and give a title. You have options to" Allow vote" and "Allow search"
3) You will be returned a URL  for your on-line flash.
4) The speed of Swfcabin to play flash is quite good.
.