Skip to content
Jul 17 10

(Jquery Plugin)lightbox for jquery

by Wison

Today,i would like to introduct to you about lightBox for jquery,I had tried to made such a effect,but it was not so perfect,or i did not find the suitable plugin,but i will record one that adapted to me here now.
I find the plugin by searching ‘lightbox for jquery‘,i it is really good.Just one jquery file,one simple css file and the required images.
You can use it by this way:

<script type=”text/javascript” src=”js/jquery.js”></script>
<script type=”text/javascript” src=”js/jquery.lightbox.js”></script>
<link rel=”stylesheet” type=”text/css” href=”css/jquery.lightbox-0.5.css” media=”screen” />
<script type=”text/javascript”>
$(function() {
$(‘#gallery a’).lightBox();
});

There are a few options to set to customize your own favourite style,include
“overlayBgColor”: Background color to overlay;
“overlayOpacity”:Opacity value to overlay;
“fixedNavigation”:Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface;
“imageLoading”:Path and the name of the loading icon;
“imageBtnPrev”:Path and the name of the prev button image;
“imageBtnNext”:Path and the name of the next button image;
“imageBtnClose”:Path and the name of the close btn;
“imageBlank”:Path and the name of a blank image;
There are alse shortcut for you to use this plugin,for example:to close the interface with letter “c”,to show the previous image with letter “p”,to show the next image with letter “n”.
See a demo ,click here.This plugin lightbox for jquery is really simple,i wish you would like it.

This tutorial of jquery plugin is from dev-tricks.com

Jul 9 10

QuickTip:jquery ajax php tutorial

by Wison

This tutorial is about the usage of jquery’s ajax method and php to develop a rich website.You can get your result without doing a submit,it reduces the http requests to the web server,makes it comes true that just refresh local part of the page.
I have use it for several projects.Here i will show you how to do it.
First,you should get the page link to the jquery labrary.
Second,to realize your goal.

$.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});

Above is the basic usage,to make use of the returned HTML, we can implement a success handler,All element of the test.html will be returned.In this case,you can give the returned html to an element or do check.
The sample is so simple,and you needn’t use $.ajax,which make the ajax process seems to more complex,you can use $.load or $.get instead it.
Here are a serial of examples to make you know more about interactive of jquery ajax php:
Example 1: Load and execute a JavaScript file.

$.ajax({
   type: "GET",
   url: "test.js",
   dataType: "script"
 });

Example 2: Save some data to the server and notify the user once it’s complete.

$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
 });

Example 3: Retrieve the latest version of an HTML page.

$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    $("#results").append(html);
  }
});

Example 4: Loads data synchronously. Blocks the browser while the requests is active. It is better to block user interaction by other means when synchronization is necessary.

var html = $.ajax({
  url: "some.php",
  async: false
 }).responseText;

Example 5: Sends an xml document as data to the server. By setting the processData option to false, the automatic conversion of data to strings is prevented.

var xmlDocument = [create xml document];
 $.ajax({
   url: "page.php",
   processData: false,
   data: xmlDocument,
   success: handleResponse
 });

Example 6: Sends an id as data to the server, save some data to the server and notify the user once it’s complete. Note that this usage – returning the result of the call into a variable – requires a synchronous (blocking) request! (async:false)

bodyContent = $.ajax({
      url: "script.php",
      global: false,
      type: "POST",
      data: ({id : this.getAttribute('id')}),
      dataType: "html",
      async:false,
      success: function(msg){
         alert(msg);
      }
   }
).responseText;

I want to show you what the php code like,if you just want php code to check or get some request data,for short ,what will display in your php page,what will be returned to the request not the return function.For example the echo station or just htm element.
In my past works ,i find it will be messy code when you get data from a php file,in this case you can code the page to utf-8.
For more data about messy code from jquery ajax php,you can refferr refer to http://www.lam5.cn/archives/161/.
And many other params you will find them in detail from http://api.jquery.com/jQuery.ajax/.

Jul 8 10

The defference between include,include_once,require,require_once

by Wison

I have been work with PHP coding for more than one year,and i have finished several website with it.
Today i make a summery of ‘include,include_once,require,require_once’ in PHP coding.

Include
The include() statement includes and evaluates the specified file.

Include Once
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. As the name suggests, it will be included just once.

Require
require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, don’t hesitate to use require() if you want a missing file to halt processing of the page.

Require Once
The require_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the require() statement, with the only difference being that if the code from a file has already been included, it will not be included again.

Remember the difference is the basic use of PHP.do it!

Jul 3 10

网易邮箱被黑客攻击事件的影响

by Wison

今天网易发生了一件比较严重的时间,其旗下的邮件系统被黑客攻击了。无意中在网上发现这条新闻,特别的震惊。
作为中国国内最大的邮件系统,有相当大部分国内网民使用的是网易的免费邮箱,而一直以来网易邮箱的口碑也是很好的,大家都相信偌大的网易公司能够保证自己的personal infomations,对于其技术系统一直都很信任。包括自己,孙然也拥有gmail但是,绝大多数邮件还是通过网易的163邮箱来进行收发的,但是今天的黑客攻击事件,网易公司在第一时间已经对此事件发表了声明,其员工泄露了管理密码造成了此事件的发生,但是事实如何,大家心理面可能也有共识。我也不想多说什么了。
但是,此类事件的发生肯定降低了部分中国网民对网易的信任度,对其能保证自己的隐私不被侵犯肯定有了很大的怀疑。
而对国内网民影响比较大的gmail的用户数量肯定在某些程度上会有增长。
但是,从长远意义来讲,此事件并不能造成很大的影响,毕竟网民身在国内,你可以不去使用网易邮箱,但是你不能忽略国内大品牌的影响力。
从某种意义来讲,本人还是比较赞同使用网易邮箱的,原因无他,我们是中国人,对于自己国内的品牌一定要支持,尽管某方面不信任。
尽管你此时会产生种种的怀疑或者看法,但是请保留对我们国产企业的支持,如果我们自己都不拥护,还准备让谁来拥护了?如果没人拥护了,中国本来发展相对缓慢的互联网技术从何谈发展?大家应该明白,此事件的发生,网易公司也会认识到自身的问题,包括技术,管理等,不敢保证以后此类事件的发生,但是他会尽量用自己的努力来确保我们的利益!
支持网易!支持网易邮箱!

Jul 3 10

(Quick Tip)basic tutorial of setcookie (php and javascript)

by Wison

As a developer,you may have heard about cookie,but what excatly are they,when we can use them?I’ll tell you about that.After reading this toturial you will actually learn how to set cookie safely in your applacation.
At the begining,you might would like to know what you can do with cookies.
Nowadays,cookie is used widely,such as saving user setting like name,language,location or screen size ,you may want to sace the client’s preferred language to a cookie ,with these cookie you can know the user’s favrite choose for your site and do it when the action appear again.The widely use of cookie is the shopping cart,thanks to cookies people are able to keep items in their cart even they disconnecting from the shop.For a word,you can use cookies do what ever you would like them to do.
chapter one:cookies in PHP
There are seven params for this function when you try to set one.
$name:each cookie must has an unique name for browser keeping them apart
$value:the data you want the cookie to hold
$expire:the time signs when the cookie is available
$path:in which path the cookie can be use for the domain
$domain:excatly for this domain,you can use the domain,but if you set cookie for “www.test.com”,the cookie is also active for the subdomain of it,include the parent main domain “www.test.com”
$secure:you can make it “true” or “false”,it means whether you make the cookie available only for the https connection is established
$httponly:the same value “true” or “false”,to make the cookie available only for the http protocol(not for javascript)
Blow is an example of usage of cookie for PHP:

<?php
setcookie( 'clientname', 'Peter Griffin', time()+60*30, '/example/', 'test.test.com', false,true);
?>

The code make a cookie named clientname and the value is Peter Gfiffin,it will not be available after 60*30 seconds(30 minutes),the cookie is attach to domain “test.test.com”,you can use the cookie if a http protocol is established and it is just for http protocol,not javascript.
Awesome!
With my tutorial,you have learn how to make a cookie,next i will show you something important of cookie and then how to get the value of your cookie.
To prevent cookie hogging huge hardspace of the client,your cookie can’t be lager than 4096 bytes(4kb) and the number of each domain is also limited,that is twenty cookies.Another thing is you must avoid set the private features to the server automatically,for cookies are usually sent through a non-secure connection,so the content could easily be seen by any potential attackers.
How to get my cookie and to decide whether i have logined or not?
There is a evronment variable $_COOKIE[],it is an array,your total cookies will been put in it, so you can get any cookie like this:$_COOKIE['username'].
All you have seen above,is the basic use of cookie in php,next i will show you how to do with id in javascript.
Javascript doesn’t offer a nice solution of cookie like php,but it is still widely used in client-sides.As the snippet below:

//get current date
var expiredate = new Date();
//increase date by 5 hours
expiredate.setHours( expiredate.getHours() + 5);
document.cookie = 'cookiename=cookievalue; expires='  + expiredate.toUTCString() + 'path=/example/; domain=test.envato.com';

Have you noticed it a similar usage with php?
Yes,the syntax is quite similar with php.

var cookieName = 'testcookiename';
var textArray = document.cookie.split(';'); //put all the parts of the string in an array
for(var i = 0; i < textArray.length; i++){ // loop though all string pieces
var textPiece = textArray[i]; //contains 1 string piece
 //filter beginning spaces
while(textPiece(0)==' ') textPiece = textPiece.substring(1,textPiece.length);
//if the textpiece contains our cookies name
if (textPiece.indexOf(cookieName)== 0){
 //return whats after the cookies name
return textPiece.substring(cookieName.length,c.length);
}
}

O,no,it makes me headache to read cookie set by javascript!It is a bad experience!
Luckily guys,i have find two function to do it.

function writeCookie(cookieName, cookieValue, expireHours, path, domain){
var date =  new Date();
date.setHours(date.getHours + expireHours);
document.cookie = cookieName + '=' + cookieValue + '; expires=' + date + '; path=' + path + '; domain=' + domain;
}  

function readCookie(cookieName){
var textArray = document.cookie.split(';');
for(var i = 0; i < textArray.length; i++){
var textPiece = textArray[i];
while(textPiece(0)==' ') textPiece = textPiece.substring(1,textPiece.length);
if (textPiece.indexOf(cookieName)== 0) return textPiece.substring(cookieName.length,c.length);
}
}

Please do bear in mind that these snippets don’t contain any error checking.
Best practices
1.you should never leave sensitive data in cookie like the user’s personal infomation.
2.Always fileter strings and numbers from cookies.An attacker could write malicious data to cookie in order to do something you don’t want your service to do.
3.Try to estimate how long the cookie should be valid,and set the expiration date accordingly.
4.Always set the secure and httponly to meet your application demands. If your application doesn’t edit the cookies with JavaScript, enable httponly. If you always have an HTTPS connection, enable secure. This improves the data’s integrity and confidentiality.

This toturial is mostly modified form nettut,which i offen find news toturial to study,i like nettut,it is very useful.
I hope this toturial will meet your need for a chance.

Jun 29 10

Have you ever see a less.js(faster css)

by Wison

Can you image css can do more faster in your page with some technology?
It is not a new technology,but in our country we use it less,and many people have never see about it.
This technology use variables,opterators,mix-ins,even nested selectors when creat stylesheet , can do it more flexibility.
Google offers us the file of less.js in this link http://lesscss.googlecode.com/files/less-1.0.18.min.js,and when can reference it use the javascript method.

<script type="text/javascript" src="http://lesscss.googlecode.com/files/less-1.0.18.min.js"></script>

Before you link to this js file,you should link to your stylesheet .And you can link to your stylesheet use an extension of .less,not .css when you change the rel attribute to “stylesheet/less”.
Have fun!
Unless you finished that,you can make your stylesheet more flexbiliable.
Here is an example:
Variables

@brand_color: #4D926F;

#header {
color: @brand_color;
}

h2 {
color: @brand_color;
}

Mixins

.rounded_corners (@radius: 5px) {
-moz-border-radius: @radius;
-webkit-border-radius: @radius;
border-radius: @radius;
}

#header {
.rounded_corners;
}

#footer {
.rounded_corners(10px);
}

Nested Rules

#header {
color: red;
a {
font-weight: bold;
text-decoration: none;
}
}

Operations

@the-border: 1px;
@base-color: #111;

#header {
color: @base-color * 3;
border-left: @the-border;
border-right: @the-border * 2;
}

#footer {
color: (@base-color + #111) * 1.5;
}

For more concepts and the DOCs you can visited http://lesscss.org/.

Jun 29 10

Google may quite business in China , just because of icp license

by Wison
I read this article just now,and realized that google my quite business in China because google.cn ‘s license will be renewal and google will not be able to continue in china.
Google.cn’s icp license will not be available after 2010.06.30,it is the end.
Just after read the article i open google.cn in my browser and the page tell me that google has been transplate to google.com.hk.
This is just because google want to do her best to meet our demand , but in some reason , China govement want it to filter something he dont want to be find by internet users in china,so that is the contradiction.
From a survey,internet in China,70% users will use Baidu.com to find their answers,though less people use goole.com,i think it is better than baidu in searching result exactly,which result in most of the developer use google.com to suffer the internet,and i like it,too.
For me,when i learn to use PHP in my work,there are so many problem i can solve,so i will find help from internet by google,it can do me the favor better.
If google quite from Chinese market,it will be affected to many people from rearcher to B2C companies,and others who rely on google and forgin countries to made their lives.
In my option,i really dont want google quite from Chinese marketing.
But if it comes,i will not give up to use google,i love google and her products.
Best wishes to google!
Jun 28 10

Something about internet marketing

by Wison
These days i have been reading the book about google awords,which i bought in LuoYang.Though i haven’t finished read it, but from what i had read and what i find in the net,i saw a space i had never thought about.
It can be see,long long ago,i construct my website about qq zone when i was in my university,i had done it with google awords,and i benifited from it,just a little.
The book called my memory,everything about internet marketing,google awords and about the B2C commerce,i decide to do something to continue it.
First,i will write my diray in English,and write story , my study ,my feelings in my blog.
Second,i learn to use SEO and internet marketing,find somethig even strang to most of us,do research about it .
All of these thing will been done in my personal space and time,in other i will go on my PHP studying.
Less thing to write,but i will stick to do it!
Jun 21 10

tutorial:how to use header function in php

by Wison

The header function has a powerful energy .you can do many things with this function.
The Usage of header function:

// See related links for more status codes

// Use this header instruction to fix 404 headers
// produced by url rewriting...
header('HTTP/1.1 200 OK');

// Page was not found:
header('HTTP/1.1 404 Not Found');

// Access forbidden:
header('HTTP/1.1 403 Forbidden');

// The page moved permanently should be used for
// all redrictions, because search engines know
// what's going on and can easily update their urls.
header('HTTP/1.1 301 Moved Permanently');

// Server error
header('HTTP/1.1 500 Internal Server Error');

// Redirect to a new location:
header('Location: http://www.example.org/');

// Redriect with a delay:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';

// you can also use the HTML syntax:
// <meta http-equiv="refresh" content="10;http://www.example.org/ />

// override X-Powered-By value
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');

// content language (en = English)
header('Content-language: en');

// last modified (good for caching)
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');

// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');

// set content length (good for caching):
header('Content-Length: 1234');

// Headers for an download:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
// load the file to send:
readfile('example.zip');

// Disable caching of the current document:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');

// set content type:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); // plain text file
header('Content-Type: image/jpeg'); // JPG picture
header('Content-Type: application/zip'); // ZIP file
header('Content-Type: application/pdf'); // PDF file
header('Content-Type: audio/mpeg'); // Audio MPEG (MP3,...) file
header('Content-Type: application/x-shockwave-flash'); // Flash animation

// show sign in box
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';
print 'enters wrong login data';

This tutorial is from the internet,to teach us usage of header,wish helpful.

Jun 12 10

how to import excel data into mysql

by Wison
There is an easy way to import excel data into mysql,for a word just use a mysql sentence.
From the article i reffered,just use five steps.

but i think it only one step,because you can do the mysql command not only use the command line but php function.
The important thing to do this is to know this command:

LOAD DATA LOCAL INFILE ‘C:\\temp\\yourfile.csv’ INTO TABLE database.table FIELDS TERMINATED BY ‘;’ ENCLOSED BY ‘”‘ LINES TERMINATED BY ‘\r\n’ (field1, field2);

next i will let you know the key words in this command:

* TERMINATED BY – this is why I included step 2. I thought a csv would default to comma separated but at least in my case semicolon was the deafult
* ENCLOSED BY – my data was not enclosed by anything so I left this as empty string ”
* LINES TERMINATED BY – at first I tried with only ‘\n’ but had to add the ‘\r’ to get rid of a carriage return character being imported into the database
* Also make sure that if you do not import into the primary key field/column that it has auto increment on, otherwhise only the first row will be imported

this article was put in forgin zone ,so i have no time to debug it right or wrong.

i wish someone who flash this article can do me a favor,and tell me other methods of “how to import excel data into mysql“.