<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IT Blog &#187; class</title>
	<atom:link href="http://blog.thuongtin.net/tag/class/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thuongtin.net</link>
	<description>php, sql, autoit, javascript, c, html</description>
	<lastBuildDate>Tue, 15 Sep 2009 00:57:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>utf8 substr</title>
		<link>http://blog.thuongtin.net/2008/11/14/utf8-substr/</link>
		<comments>http://blog.thuongtin.net/2008/11/14/utf8-substr/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 06:34:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[substr]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=333</guid>
		<description><![CDATA[utf8 substr

&#60;?php
function utf8_substr($str,$from,$len){
return preg_replace('#^(?:[\x00-\x7F]&#124;[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
'((?:[\x00-\x7F]&#124;[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',
'$1',$str);
}
echo utf8_substr('người đi xa mãi',0,10);
?&#62;

Related Posts:Hàm kiểm tra file sizeLấy thời gian của tập tin .flvClass CurlHàm tính tuổiYoutube Download Link Generator]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">utf8 substr</p>
<pre class="brush: php;">
&lt;?php
function utf8_substr($str,$from,$len){
return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',
'$1',$str);
}
echo utf8_substr('người đi xa mãi',0,10);
?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/09/11/ham-kiem-tra-file-size/" rel="bookmark">Hàm kiểm tra file size</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/lay-thoi-gian-cua-tap-tin-flv/" rel="bookmark">Lấy thời gian của tập tin .flv</a></li><li><a href="http://blog.thuongtin.net/2008/09/10/class-curl/" rel="bookmark">Class Curl</a></li><li><a href="http://blog.thuongtin.net/2008/10/10/ham-tinh-tuoi/" rel="bookmark">Hàm tính tuổi</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/youtube-download-link-generator/" rel="bookmark">Youtube Download Link Generator</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=333&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/14/utf8-substr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login and Logout using Sessions and Cookies</title>
		<link>http://blog.thuongtin.net/2008/11/04/login-and-logout-using-sessions-and-cookies/</link>
		<comments>http://blog.thuongtin.net/2008/11/04/login-and-logout-using-sessions-and-cookies/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 03:36:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[login]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=300</guid>
		<description><![CDATA[Login and Logout using Sessions and Cookies.
1. Tại file functions.php với nội dung:
&#60;?php

function createsessions($username,$password)
{
//Add additional member to Session array as per requirement
session_register();

$_SESSION[&#34;gdusername&#34;] = $username;
$_SESSION[&#34;gdpassword&#34;] = md5($password);

if(isset($_POST['remme']))
{
//Add additional member to cookie array as per requirement
setcookie(&#34;gdusername&#34;, $_SESSION['gdusername'], time()+60*60*24*100, &#34;/&#34;);
setcookie(&#34;gdpassword&#34;, $_SESSION['gdpassword'], time()+60*60*24*100, &#34;/&#34;);
return;
}
}

function clearsessionscookies()
{
unset($_SESSION['gdusername']);
unset($_SESSION['gdpassword']);

session_unset();
session_destroy();

setcookie (&#34;gdusername&#34;, &#34;&#34;,time()-60*60*24*100, &#34;/&#34;);
setcookie (&#34;gdpassword&#34;, &#34;&#34;,time()-60*60*24*100, &#34;/&#34;);
}

function confirmUser($username,$password)
{
// $md5pass = md5($password); // Not needed any ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Login and Logout using Sessions and Cookies.</p>
<p>1. Tại file functions.php với nội dung:</p>
<pre class="brush: php;">&lt;?php

function createsessions($username,$password)
{
//Add additional member to Session array as per requirement
session_register();

$_SESSION[&quot;gdusername&quot;] = $username;
$_SESSION[&quot;gdpassword&quot;] = md5($password);

if(isset($_POST['remme']))
{
//Add additional member to cookie array as per requirement
setcookie(&quot;gdusername&quot;, $_SESSION['gdusername'], time()+60*60*24*100, &quot;/&quot;);
setcookie(&quot;gdpassword&quot;, $_SESSION['gdpassword'], time()+60*60*24*100, &quot;/&quot;);
return;
}
}

function clearsessionscookies()
{
unset($_SESSION['gdusername']);
unset($_SESSION['gdpassword']);

session_unset();
session_destroy();

setcookie (&quot;gdusername&quot;, &quot;&quot;,time()-60*60*24*100, &quot;/&quot;);
setcookie (&quot;gdpassword&quot;, &quot;&quot;,time()-60*60*24*100, &quot;/&quot;);
}

function confirmUser($username,$password)
{
// $md5pass = md5($password); // Not needed any more as pointed by ted_chou12

/* Validate from the database but as for now just demo username and password */
if($username == &quot;demo&quot; &amp;&amp; $password = &quot;demo&quot;)
return true;
else
return false;
}

function checkLoggedin()
{
if(isset($_SESSION['gdusername']) AND isset($_SESSION['gdpassword']))
return true;
elseif(isset($_COOKIE['gdusername']) &amp;&amp; isset($_COOKIE['gdpassword']))
{
if(confirmUser($_COOKIE['gdusername'],$_COOKIE['gdpassword']))
{
createsessions($_COOKIE['gdusername'],$_COOKIE['gdpassword']);
return true;
}
else
{
clearsessionscookies();
return false;
}
}
else
return false;
}
?&gt;
</pre>
<p>File index.php</p>
<pre class="brush: php;">&lt;?php
ob_start();
session_start();

require_once (&quot;functions.php&quot;);

if (checkLoggedin())
echo &quot;&lt;H1&gt;You are already logged in - &lt;A href = &quot;login.php?do=logout&quot;&gt;logout&lt;/A&gt;&lt;/h1&gt;&quot;;
else
echo &quot;&lt;H1&gt;You are not logged in - &lt;A href = &quot;login.php&quot;&gt;login&lt;/A&gt;&lt;/h1&gt;&lt;/h1&gt;&quot;;
?&gt;
</pre>
<p>File login.php</p>
<pre class="brush: php;">&lt;?php

ob_start();
session_start();

require_once (&quot;functions.php&quot;);

$returnurl = urlencode(isset($_GET[&quot;returnurl&quot;])?$_GET[&quot;returnurl&quot;]:&quot;&quot;);
if($returnurl == &quot;&quot;)
$returnurl = urlencode(isset($_POST[&quot;returnurl&quot;])?$_POST[&quot;returnurl&quot;]:&quot;&quot;);

$do = isset($_GET[&quot;do&quot;])?$_GET[&quot;do&quot;]:&quot;&quot;;

$do = strtolower($do);

switch($do)
{
case &quot;&quot;:
if (checkLoggedin())
{
echo &quot;&lt;H1&gt;You are already logged in - &lt;A href = &quot;login.php?do=logout&quot;&gt;logout&lt;/A&gt;&lt;/h1&gt;&quot;;
}
else
{
?&gt;
&lt;form NAME=&quot;login1&quot; ACTION=&quot;login.php?do=login&quot; METHOD=&quot;POST&quot; ONSUBMIT=&quot;return aValidator();&quot;&gt;
&lt;input TYPE=&quot;hidden&quot; name=&quot;returnurl&quot; value=&quot;&lt;?$returnurl?&gt;&quot;&gt;
&lt;TABLE cellspacing=&quot;3&quot;&gt;
&lt;TR&gt;
&lt;TD&gt;Username:&lt;/TD&gt;
&lt;TD&gt;&lt;input TYPE=&quot;TEXT&quot; NAME=&quot;username&quot;&gt;&lt;/TD&gt;
&lt;TD&gt;Password:&lt;/TD&gt;
&lt;TD&gt;&lt;input TYPE=&quot;PASSWORD&quot; NAME=&quot;password&quot;&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan=&quot;4&quot; ALIGN=&quot;center&quot;&gt;&lt;input TYPE=&quot;CHECKBOX&quot; NAME=&quot;remme&quot;&gt;&amp;nbsp;Remember me for the next time I visit&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD ALIGN=&quot;CENTER&quot; COLSPAN=&quot;4&quot;&gt;&lt;input TYPE=&quot;SUBMIT&quot; name=&quot;submit&quot; value=&quot;Login&quot;&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/form&gt;
&lt;/TABLE&gt;
&lt;?
}
break;
case &quot;login&quot;:
$username = isset($_POST[&quot;username&quot;])?$_POST[&quot;username&quot;]:&quot;&quot;;
$password = isset($_POST[&quot;password&quot;])?$_POST[&quot;password&quot;]:&quot;&quot;;

if ($username==&quot;&quot; or $password==&quot;&quot; )
{
echo &quot;&lt;h1&gt;Username or password is blank&lt;/h1&gt;&quot;;
clearsessionscookies();
header(&quot;location: login.php?returnurl=$returnurl&quot;);
}
else
{
if(confirmuser($username,md5($password))) // As pointed out by asgard2005
{
createsessions($username,$password);
if ($returnurl&lt;&gt;&quot;&quot;)
header(&quot;location: $returnurl&quot;);
else
{
header(&quot;Location: index.php&quot;);
}
}
else
{
echo &quot;&lt;h1&gt;Invalid Username and/Or password&lt;/h1&gt;&quot;;
clearsessionscookies();
header(&quot;location: login.php?returnurl=$returnurl&quot;);
}
}
break;
case &quot;logout&quot;:
clearsessionscookies();
header(&quot;location: index.php&quot;);
break;
}
?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/09/12/class-login/" rel="bookmark">Class login</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/file-sao-luu-du-lieu/" rel="bookmark">File sao lưu dữ liệu</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/tao-1-file-download-file/" rel="bookmark">Tạo 1 file download file</a></li><li><a href="http://blog.thuongtin.net/2008/10/22/yahoo-messenger-api/" rel="bookmark">Yahoo Messenger API</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/grab-link-megaroticcom/" rel="bookmark">Grab link megarotic.com</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=300&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/04/login-and-logout-using-sessions-and-cookies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lập trình hướng đối tượng căn bản</title>
		<link>http://blog.thuongtin.net/2008/11/03/lap-trinh-huong-doi-tuong-can-ban/</link>
		<comments>http://blog.thuongtin.net/2008/11/03/lap-trinh-huong-doi-tuong-can-ban/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 08:11:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=289</guid>
		<description><![CDATA[Bài viết này là Level 2 khóa học Zend tại  wWw.Zend.Vn
Phần I: Tổng quan về lập trình hướng đối tượng
1. Lập trình hướng đối tượng là  gì?
Lập trình hướng đối tượng (gọi tắt là OOP, từ chữ Anh ngữ  object-oriented programming), hay còn gọi là lập trình định hướng đối tượng, là  ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Bài viết này là Level 2 khóa học Zend tại  <a href="http://zend.vn" target="_blank">wWw.Zend.Vn</a></p>
<div class="title"><strong>Phần I: Tổng quan về lập trình hướng đối tượng</strong></div>
<div class="content"><strong><span class="title-in-content">1. Lập trình hướng đối tượng là  gì?</span></strong><br />
Lập trình hướng đối tượng (gọi tắt là OOP, từ chữ Anh ngữ  object-oriented programming), hay còn gọi là lập trình định hướng đối tượng, là  kĩ thuật lập trình hỗ trợ công nghệ đối tượng. OOP được xem là giúp tăng năng  suất, đơn giản hóa độ phức tạp khi bảo trì cũng như mở rộng phần mềm bằng cách  cho phép lập trình viên tập trung vào các đối tượng phần mềm ở bậc cao hơn.  Ngoài ra, nhiều người còn cho rằng OOP dễ tiếp thu hơn cho những người mới học  về lập trình hơn là các phương pháp trước đó.</p>
<p>Một cách giản lược, đây là  khái niệm và là một nỗ lực nhằm giảm nhẹ các thao tác viết mã cho người lập  trình, cho phép họ tạo ra các ứng dụng mà các yếu tố bên ngoài có thể tương tác  với các chương trình đó giống như là tương tác với các đối tượng vật  lý.</p>
<p>Những đối tượng trong một ngôn ngữ OOP là các kết hợp giữa mã và dữ  liệu mà chúng được nhìn nhận như là một đơn vị duy nhất. Mỗi đối tượng có một  tên riêng biệt và tất cả các tham chiếu đến đối tượng đó được tiến hành qua tên  của nó. Như vậy, mỗi đối tượng có khả năng nhận vào các thông báo, xử lý dữ liệu  (bên trong của nó), và gửi ra hay trả lời đến các đối tượng khác hay đến môi  trường.</p>
<p><strong><span class="title-in-content">2. Các tính chất cơ bản của lập trình hướng đối  tượng</span></strong></p>
<p>Đối tượng (object): Các dữ liệu và chỉ thị được kết hợp vào  một đơn vị đầy đủ tạo nên một đối tượng. Đơn vị này tương đương với một chương  trình con và vì thế các đối tượng sẽ được chia thành hai bộ phận chính: phần các  phương thức (method) và phần các thuộc tính (property). Trong thực tế, các  phương thức của đối tượng là các hàm và các thuộc tính của nó là các biến, các  tham số hay hằng nội tại của một đối tượng (hay nói cách khác tập hợp các dữ  liệu nội tại tạo thành thuộc tính của đối tượng). Các phương thức là phương tiện  để sử dụng một đối tượng trong khi các thuộc tính sẽ mô tả đối tượng có những  tính chất gì.</p>
<p>Các phương thức và các thuộc tính thường gắn chặt với thực  tế các đặc tính và sử dụng của một đối tượng.</p>
<p>Trong thực tế, các đối  tượng thường được trừu tượng hóa qua việc định nghĩa của các lớp  (class).</p>
<p>Tập hợp các giá trị hiện có của các thuộc tính tạo nên trạng  thái của một đối tượng.<br />
Mỗi phương thức hay mỗi dữ liệu nội tại cùng với các  tính chất được định nghĩa (bởi người lập trình) được xem là một đặc tính riêng  của đối tượng. Nếu không có gì lầm lẫn thì tập hợp các đặc tính này gọi chung là  đặc tính của đối tượng.</p>
<p><span class="title-in-content">Lập trình hướng đối  tượng là một phương pháp lập trình có các tính chất chính  sau:</span></p>
<p><span class="title-in-content">Tính trừu tượng  (abstraction):</span> Đây là khả năng của chương trình bỏ qua hay không chú ý  đến một số khía cạnh của thông tin mà nó đang trực tiếp làm việc lên, nghĩa là  nó có khả năng tập trung vào những cốt lõi cần thiết. Mỗi đối tượng phục vụ như  là một &#8220;động tử&#8221; có thể hoàn tất các công việc một cách nội bộ, báo cáo, thay  đổi trạng thái của nó và liên lạc với các đối tượng khác mà không cần cho biết  làm cách nào đối tượng tiến hành được các thao tác. Tính chất này thường được  gọi là sự trừu tượng của dữ liệu.</p>
<p>Tính trừu tượng còn thể hiện qua việc  một đối tượng ban đầu có thể có một số đặc điểm chung cho nhiều đối tượng khác  như là sự mở rộng của nó nhưng bản thân đối tượng ban đầu này có thể không có  các biện pháp thi hành. Tính trừu tượng này thường được xác định trong khái niệm  gọi là lớp trừu tượng hay hay lớp cơ sở trừu tượng.</p>
<p><span class="title-in-content">Tính đóng gói (encapsulation) và che dấu thông tin  (information hiding):</span> Tính chất này không cho phép người sử dụng các đối  tượng thay đổi trạng thái nội tại của một đối tượng. Chỉ có các phương thức nội  tại của đối tượng cho phép thay đổi trạng thái của nó. Việc cho phép môi trường  bên ngoài tác động lên các dữ liệu nội tại của một đối tượng theo cách nào là  hoàn toàn tùy thuộc vào người viết mã. Đây là tính chất đảm bảo sự toàn vẹn của  đối tượng.</p>
<p><span class="title-in-content">Tính đa hình  (polymorphism):</span> Thể hiện thông qua việc gửi các thông điệp (message).  Việc gửi các thông điệp này có thể so sánh như việc gọi các hàm bên trong của  một đối tượng. Các phương thức dùng trả lời cho một thông điệp sẽ tùy theo đối  tượng mà thông điệp đó được gửi tới sẽ có phản ứng khác nhau. Người lập trình có  thể định nghĩa một đặc tính (chẳng hạn thông qua tên của các phương thức) cho  một loạt các đối tượng gần nhau nhưng khi thi hành thì dùng cùng một tên gọi mà  sự thi hành của mỗi đối tượng sẽ tự động xảy ra tương ứng theo đặc tính của từng  đối tượng mà không bị nhầm lẫn.</p>
<p>Thí dụ khi định nghĩa hai đối tượng  &#8220;hinh_vuong&#8221; và &#8220;hinh_tron&#8221; thì có một phương thức chung là &#8220;chu_vi&#8221;. Khi gọi  phương thức này thì nếu đối tượng là &#8220;hinh_vuong&#8221; nó sẽ tính theo công thức khác  với khi đối tượng là &#8220;hinh_tron&#8221;.</p>
<p><span class="title-in-content">Tính kế  thừa (inheritance): </span>Đặc tính này cho phép một đối tượng có thể có sẵn các  đặc tính mà đối tượng khác đã có thông qua kế thừa. Điều này cho phép các đối  tượng chia sẻ hay mở rộng các đặc tính sẵn có mà không phải tiến hành định nghĩa  lại. Tuy nhiên, không phải ngôn ngữ định hướng đối tượng nào cũng có tính chất  này.</p>
<p><strong><span class="title-in-content">3. Các khái niệm liên quan đến các ngôn ngữ lập  trình OOP hiện đại</span></strong></p>
<p><strong><span class="title-in-content">Lớp  (class)</span></strong></p>
<p>Một lớp được hiểu là một kiểu dữ liệu bao gồm các thuộc  tính và các phương thức được định nghĩa từ trước. Đây là sự trừu tượng hóa của  đối tượng. Một đối tượng sẽ được xác lập khi nó được thực thể hóa từ một lớp.  Khác với kiểu dữ liệu thông thường, một lớp là một đơn vị (trừu tượng) bao gồm  sự kết hợp giữa các phương thức và các thuộc tính. Để có một đối tượng (mà có  thể được xem như là một biến) hoạt động được thì việc thực thể hóa sẽ có thể bao  gồm việc cài đặt các giá trị ban đầu của các thuộc tính cũng như việc đăng kí bộ  nhớ, mà công việc này thường được giao cho các phương thức gọi là &#8220;máy kết cấu&#8221;  (constructor) hay hàm dựng. Ngược lại khi một đối tượng thuộc về một lớp không  còn sử dụng nữa thì cũng có thể có một phương thức để xử lý gọi là &#8220;máy hủy  diệt&#8221; (destructor) hay hàm hủy.</p>
<p>Như vậy, để có được các đối tượng thì  người lập trình OOP cần phải thiết kế lớp của các đối tượng đó bằng cách xây  dựng các thuộc tính và các phương thức có các đặc tính riêng.</p>
<p>Mỗi một  phương thức hay một thuộc tính đầy đủ của một lớp còn được gọi tên là một thành  viên (member) của lớp đó.</p>
<p><strong><span class="title-in-content">Lớp con  (subclass)</span></strong><br />
Lớp con là một lớp thông thường nhưng có thêm tính chất kế  thừa một phần hay toàn bộ các đặc tính của một lớp khác. Lớp mà chia sẽ sự kế  thừa gọi là lớp phụ mẫu (parent class).</p>
<p><span class="title-in-content">Lớp  trừu tượng hay lớp cơ sở trừu tượng (abstract class)</span></p>
<p>Lớp trừu  tượng là một lớp mà nó không thể thực thể hóa thành một đối tượng thực dụng  được. Lớp này được thiết kế nhằm tạo ra một lớp có các đặc tính tổng quát nhưng  bản thân lớp đó chưa có ý nghĩa (hay không đủ ý nghĩa) để có thể tiến hành viết  mã cho việc thực thể hóa. (xem thí dụ)</p>
<p>Thí dụ: Lớp &#8220;hinh_phang&#8221; được định  nghĩa không có dữ liệu nội tại và chỉ có các phương thức (hàm nội tại)  &#8220;tinh_chu_vi&#8221;, &#8220;tinh_dien_tich&#8221;. Nhưng vì lớp hình_phẳng này chưa xác định được  đầy đủ các đặc tính của nó (cụ thể các biến nội tại là tọa độ các đỉnh nếu là đa  giác, là đường bán kính và toạ độ tâm nếu là hình tròn, &#8230;) nên nó chỉ có thể  được viết thành một lớp trừu tượng. Sau đó, người lập trình có thể tạo ra các  lớp con chẳng hạn như là lớp &#8220;tam_giac&#8221;, lớp &#8220;hinh_tron&#8221;, lớp &#8220;tu_giac&#8221;,&#8230;. Và  trong các lớp con này người viết mã sẽ cung cấp các dữ liệu nội tại (như là biến  nội tại r làm bán kính và hằng số nội tại Pi cho lớp &#8220;hinh_tron&#8221; và sau đó viết  mã cụ thể cho các phương thức &#8220;tinh_chu_vi&#8221; và &#8220;tinh_dien_tich&#8221;).</p>
<p><strong><span class="title-in-content">Phương Thức (method)</span></strong></p>
<p>Là hàm nội tại của một  lớp (hay một đối tượng). Tùy theo đặc tính mà người lập trình gán cho, một  phương pháp có thể chỉ được gọi bên trong các hàm khác của lớp đó, có thể cho  phép các câu lệnh bên ngoài lớp gọi tới nó, hay chỉ cho phép các lớp có quan hệ  đặc biệt như là quan hệ lớp con, và quan hệ bạn bè (friend) được phép gọi tới  nó. Mỗi phương pháp đều có thể có kiểu trả về, chúng có thể trả các kiểu dữ liệu  cổ điển hay trả về một kiểu là một lớp đã được định nghĩa từ trước. Một tên gọi  khác của phương pháp của một lớp là hàm thành viên.</p>
<p>Người ta còn định  nghĩa thêm vài loại phương pháp đặc biệt:</p>
<p>Hàm dựng (constructor) là hàm  được dùng để cài đặt các giá tri ban đầu cho các biến nội tại và đôi khi còn  dùng để khai báo về việc xử dụng bộ nhớ.<br />
Hàm hủy (destructor) là hàm dùng vào  việc làm sạch bộ nhớ và hủy bỏ tên của một đối tượng sau khi đã dùng xong, trong  đó có thể bao gồm cả việc xóa các con trỏ nội tại và trả về các phần bộ nhớ mà  đối tượng đã dùng.<br />
Trong một số trường hợp thì hàm hủy hay hàm dựng có thể  được tự động hóa bởi ngôn ngữ OOP như là trường hợp của Visual C++,  C#.</p>
<p>Tiện ích (utility) là các hàm chỉ họat động bên trong của một lớp mà  không cho phép môi trường bên ngoài gọi tới. Các hàm này có thể là những tính  toán trung gian nội bộ của một đối tượng mà xét thấy không cần thiết phải cho  thế giới bên ngoài của đối tượng biết là gì.</p>
<p><strong><span class="title-in-content">Thuộc tính (attribute)</span></strong></p>
<p>Thuộc tính của một  lớp bao gồm các biến, các hằng, hay tham số nội tại của lớp đó. Ở đây, vai trò  quan trọng nhất của các thuộc tính là các biến vì chúng sẽ có thể bị thay đổi  trong suốt quá trình hoạt động của một đối tượng. Các thuộc tính có thể được xác  định kiểu và kiểu của chúng có thể là các kiểu dữ liệu cổ điển hay đó là một lớp  đã định nghĩa từ trước. Như đã ghi, khi một lớp đã được thực thể hoá thành đối  tượng cụ thể thì tập họp các giá trị của các biến nội tại làm thành trạng thái  của đối tượng. Giống như trường hợp của phương pháp, tùy theo người viết mã,  biến nội tại có thể chỉ được dùng bên trong các phương pháp của chính lớp đó, có  thể cho phép các câu lệnh bên ngoài lớp, hay chỉ cho phép các lớp có quan hệ đặc  biệt như là quan hệ lớp con, (và quan hệ bạn bè (friend) trong C++) được phép  dùng tới nó (hay thay đổi giá trị của nó). Mỗi thuộc tính của một lớp còn được  gọi là thành viên dữ liệu của lớp đó.</p>
<p><strong><span class="title-in-content">Thực  thể (instance)</span></strong></p>
<p>Thực thể hóa (instantiate) là quá trình khai báo để  có một tên (có thể được xem như là một biến) trở thành một đối tượng từ một lớp  nào đó.</p>
<p>Một lớp sau khi được tiến hành thực thể hóa để có một đối tượng  cụ thể gọi là một thực thể. Hay nói ngược lại một thực thể là một đối tượng  riêng lẽ của một lớp đã định trước. Như các biến thông thường, hai thực thể của  cùng một lớp có thể có trạng thái nội tại khác nhau (xác định bởi các giá trị  hiện có của các biến nội tại) và do đó hoàn toàn độc lập nhau nếu không có yêu  cầu gì đặc biệt từ người lập trình.</p>
<p><strong><span class="title-in-content">Công  cộng (public)</span></strong></p>
<p>Công cộng là một tính chất được dùng để gán cho các  phương pháp, các biến nội tại, hay các lớp mà khi khai báo thì người lập trình  đã cho phép các câu lệnh bên ngoài cũng như các đối tượng khác được phép dùng  đến nó.</p>
<p>Thí dụ: Trong C++ khai báo public: int my_var; thì biến my_var có  hai tính chất là tính công cộng và là một integer cả hai tính chất này hợp thành  đặc tính của biến my_var khiến nó có thể được xử dụng hay thay đổi giá trị của  nó (bởi các câu lệnh) ở mọi nơi bên ngoài lẫn bên trong của lớp.</p>
<p><strong><span class="title-in-content">Riêng tư (private)</span></strong></p>
<p>Riêng tư là sự thể hiện  tính chất đóng mạnh nhất (của một đặc tính hay một lớp). Khi dùng tính chất này  gán cho một biến, một phương pháp thì biến hay phương pháp đó chỉ có thể được sử  dụng bên trong của lớp mà chúng được định nghĩa. Mọi nỗ lực dùng đến chúng từ  bên ngoài qua các câu lệnh hay từ các lớp con sẽ bị phủ nhận hay bị  lỗi.</p>
<p><strong><span class="title-in-content">Bảo tồn (protected)</span></strong></p>
<p>Tùy  theo ngôn ngữ, sẽ có vài điểm nhỏ khác nhau về cách hiểu tính chất này. Nhìn  chung đây là tính chất mà mà khi dùng để áp dụng cho các phương pháp, các biến  nội tại, hay các lớp thì chỉ có trong nội bộ của lớp đó hay các lớp con của nó  (hay trong nội bộ một gói như trong Java) được phép gọi đến hay dùng đến các  phương pháp, biến hay lớp đó.</p>
<p>So với tính chất riêng tư thì tính bảo tồn  rộng rãi hơn về nghĩa chia sẻ dữ liệu hay chức năng. Nó cho phép một số trường  hợp được dùng tới các đặc tính của một lớp (từ một lớp con chẳng  hạn).</p>
<p>Lưu ý: Các tính chất cộng cộng, riêng tư và bảo tồn đôi khi còn  được dùng để chỉ thị cho một lớp con cách thức kế thừa một lớp cha mẹ như trong  C++.</p>
<p><strong><span class="title-in-content">Đa kế thừa (muliple  inheritance)</span></strong></p>
<p>Đây là một tính chất cho phép một lớp con có khả năng  kế thừa trực tiếp cùng lúc nhiều lớp khác.</p>
<p>Vài điểm cần lưu ý khi viết mã  dùng tính chất đa kế thừa:</p>
<p>Khi muốn có một sự kế thừa từ nhiều lớp phụ  mẫu thì các lớp này cần phải độc lập và đặc biệt tên của các dữ liệu hay hàm cho  phép kế thừa phải có tên khác nhau để tránh lỗi &#8220;ambiguilty&#8221;. Bởi vì lúc đó phần  mềm chuyển dịch sẽ không thể xác định được là lớp con sẽ thừa kế tên nào của các  lớp phụ mẫu.<br />
Không phải ngôn ngữ OOP loại phân lớp nào cũng hỗ trợ cho tính  chất này.<br />
Ngoài các khái niệm trên, tùy theo ngôn ngữ, có thể sẽ có các chức  năng OOP riêng biệt được cấp thêm vào.</p></div>
<div class="title"><strong>Phần II: Các bước để tạo 1 class của 1 đối tượng</strong></div>
<div class="content">
<p>Một đối tượng thường bao gồm trạng thái (thuộc tính) và hành động</p>
<p><strong>1. Xác định đối tượng </strong><br />
Ví dụ:<br />
- Lập trình viên là 1  đối tượng<br />
- Con chó là 1 đối tượng</p>
<p><strong>2. Xác định trạng thái (thuộc tính) [attribute  (property)]</strong><br />
- Các trạng thái (thuộc tính) của lập trình viên là: Họ,  tên, ngày sinh, quê quán, giới tính, email, điện thoại, kinh nghiệm, ưu điểm,  nhược điểm, kỹ năng, tài khỏan&#8230;<br />
- Các trạng thái (thuộc tính) của con chó  là: Tên, màu lông , giống, đuôi, chân, tai, màu mắt &#8230;..</p>
<p><strong>3. Xác định hành động</strong><br />
- Các hành động (behaviour) của lập  trình viên: làm việc, ăn, ngủ, học, nghiên cứu, đi chơi, gửi tiền vào tài khỏan,  rút tiền khỏi tài khoản<br />
- Các hành động (behaviour) của con chó: sủa, vẫy  tai, chạy, ăn</div>
<div class="title-in-content"><span style="text-decoration: underline;">Ví dụ: Tạo lớp &#8216;Lập trình viên&#8217;</span></div>
<div class="content">Chúng ta tạo 1 tập tin có tên <span class="code-in-rows">class.programer.php</span> với nội dung sau:</div>
<div class="title-in-content"><strong>2.1 Khai báo các thuộc tính của đối tượng</strong></div>
<div class="code-area">
<p class="note">//class.programer.php</p>
<pre class="brush: php;">

&lt;?php
class Programer {

//Dinh nghia cac thuoc tinh cua doi tuong
public $firstName; // Ho
public $lastName; // Ten
public $birthday; // Ngay sinh
public $sex; //Giới tính
public $email;
public $phone; // dien thoai
public $experienced; // Kinh nghiem
public $advantage; // uu diem
public $weakness; // nhuoc diem
public $skill; // Ky nang

}

?&gt;
</pre>
<div class="title-in-content"><strong>2.2 Tạo hàm cấu trúc cho class</strong></div>
<div class="code-area">
<p class="note">//class.programer.php</p>
</div>
<div class="content">Chúng ta tạo 1 tập tin có tên <span class="code-in-rows">oop.php</span> với nội dung sau:</div>
<div class="code-area">
<p class="note">//oop.php</p>
<pre class="brush: php;">&lt;?php&lt;/div&gt;
&lt;/div&gt;
// Nhung file class.programer.php vao trang
include('class.programer.php');

// Goi doi tuong Programer
$objProgramer = new Programer('Hoang','14-02-1985');

// In ra thong tin cua lap trinh vien
echo $objProgramer-&gt;printInfo();

?&gt;
</pre>
<div>
<div class="content">Chúng ta sẽ được kết quả như sau</div>
<div class="code-area"><strong>Thong tin lap trinh  vien:</strong><br />
<strong>Ten:</strong> Hoang<br />
<strong>Ngay sinh:</strong> 14-02-1985</div>
<div class="content">
<p>- Theo cấu trúc chuẩn của PHP chúng ta sẽ tạo 1 hàm cấu trúc cho  class<br />
<strong>public function __construct($varLastName,  $varBirthday);</strong></p>
<p>- Khi ta gọi khai báo đối tượng <span class="code-in-rows">$objProgramer</span> với cú pháp<br />
<strong>$objProgramer = new  Programer(&#8216;Hoang&#8217;,'14-02-1985&#8242;);</strong></p>
<p>- Lúc đó 2 giá tri <span class="code-in-rows">&#8216;Hoang&#8217;</span> và <span class="code-in-rows">&#8216;14-02-1985&#8242;</span> được gán vào 2 tham số <span class="code-in-rows">$varLastName</span> và <span class="code-in-rows">$varBirthday</span>.<br />
Lệnh <span class="code-in-rows">$this-&gt;lastName = $varLastName;</span> sẽ gán giá trị  <span class="code-in-rows">$varLastName</span> vào cho thuộc tính <span class="code-in-rows">public $firstName;</span> được khai báo phí trên<br />
Tương tự  lệnh <span class="code-in-rows">$this-&gt;birthday = $varBirthday;</span> cũng sẽ  gán giá trị <span class="code-in-rows">$varBirthday</span> vào cho thuộc tính  <span class="code-in-rows">public $birthday;</span> được khai báo phí trên<br />
-  Sau khi 2 tham số <span class="code-in-rows">$varLastName</span> và <span class="code-in-rows">$varBirthday</span> được gán cho 2 thuộc tính <span class="code-in-rows">$firstName</span> và <span class="code-in-rows">$birthday</span>, lúc này bạn có thể sử dụng tùy ý 2 giá trị  này trong class bằng cú pháp <strong>$this-&gt;&lt;tên thuộc  tính&gt;</strong><br />
<strong>vd:</strong><br />
<span class="code-in-rows">$this-&gt;birthday; </span><br />
<span class="code-in-rows">$this-&gt;lastName;</span></p>
<p>- Khi đã có thông tin về đối tượng <span class="code-in-rows">objProgramer</span> bạn có thể in những thông tin đó ra bằng  cách gọi hàm <span class="code-in-rows">printInfo()</span> trong class<br />
<span class="code-in-rows">echo $objProgramer-&gt;printInfo();</span></p>
<p>- Trong hàm <span class="code-in-rows">prinInfo()</span> của <span class="code-in-rows">class Programer</span>. Hàm này này lấy các giá trị đã được  gán ở phía trên in ra kết quả</div>
<div class="content">- Trong hàm tạo cấu trúc của class ta đã truyền được 2 giá  trị cho 2 thuộc tính bây giờ ta sẽ tạo các hàm để truyền các giá trị cho các  thuộc tính còn lại. Ví dụ ta tạo hàm lấy giá trị cho thuộc tính <span class="code-in-rows">$firstName</span></div>
<div class="code-area">
<p class="note">//class.programer.php</p>
</div>
<div class="code-area">
<pre class="brush: php;">&lt;?php
class Programer {
//Dinh nghia cac thuoc tinh cua doi tuong
public $firstName; // Ho
public $lastName; // Ten
public $birthday; // Ngay sinh
public $sex; //Giới tính
public $email;
public $phone; // dien thoai
public $experienced; // Kinh nghiem
public $advantage; // uu diem
public $weakness; // nhuoc diem
public $skill; // Ky nang// Tao ham cau truc cho class
public function __construct($varLastName, $varBirthday)
{
$this-&gt;lastName = $varLastName;
$this-&gt;birthday = $varBirthday;
}

// Ham nhan gia tri cua firstName (Ho)
public function setFirstName($varFirstName)
{
$this-&gt;firstName = $varFirstName;
}

// In thông tin member
public function printInfo()
{
$info = '&lt;b&gt;Thong tin lap trinh vien:&lt;/b&gt;';
$info .= '&lt;br&gt;&lt;b&gt;Ten:&lt;/b&gt; ' . $this-&gt;lastName;
$info .= '&lt;br&gt;&lt;b&gt;Ngay sinh:&lt;/b&gt; ' . $this-&gt;birthday;
return $info;
}

}

?&gt;
</pre>
<div class="content">- Chúng ta thêm hàm <span class="code-in-rows">setFirstName($varFirstName</span>) hàm này có chức năng nhận  giá trị và truyền cho thuộc tính <span class="code-in-rows">public  $firstName;</span>.<br />
- Và sau đó chúng ta thêm 1 dòng lệnh <span class="code-in-rows">$info .= &#8216;&lt;br&gt;&lt;b&gt;Ho:&lt;/b&gt; &#8216; .  $this-&gt;firstName;</span> vào hàm <span class="code-in-rows">printInfo()</span> để in ra họ của lập trình viên<br />
- Chúng ta thêm dòng lệnh <span class="code-in-rows">$objProgramer-&gt;setFirstName(&#8216;Nguyen Van &#8216;);</span> trang  <span class="code-in-rows">oop.php</span> 1 chút để sử dụng được hàm <span class="code-in-rows">setFirstName()</span></div>
<div class="code-area">
<p class="note">//oop.php</p>
<pre class="brush: php;">

&lt;?php
// Nhung file class.programer.php vao trang
include('class.programer.php');

// Goi doi tuong Programer
$objProgramer = new Programer('Hoang','14-02-1985');

// Dua gia tri vao cho thuoc tinh $firstName trong Programer class
$objProgramer-&gt;setFirstName('Nguyen Van');

// In ra thong tin cua lap trinh vien
echo $objProgramer-&gt;printInfo();

?&gt;
</pre>
<div class="content">Tiếp theo chúng ta sẽ tiếp tục truyền giá trị vào cho từng  thuộc tính còn lại</div>
<div class="code-area">
<p class="note">//oop.php</p>
<pre class="brush: php;">

&lt;?php
/**
* Zend Framework
*
* @category Training
* @package Zend Framework Basic
* @copyright Copyright (c) 2008 Zend Vietnamese Team (http://www.zend.vn)
* @version $Id: class.programer.php 2008-02-10 01:35:30Z
* @author Marsu (ZVN Founder team)
*@email zendvn@yahoo.com OR marsu@zend.vn
*
*/

//Dinh nghia cac thuoc tinh cua doi tuong
public $firstName = null; // Ho
public $lastName; // Ten
public $birthday = null; // Ngay sinh
public $sex; //Giới tính
public $email;
public $phone; // dien thoai
public $experienced; // Kinh nghiem
public $advantage; // uu diem
public $weakness; // nhuoc diem
public $skill; // Ky nang

// Tao ham cau truc cho class
public function __construct($varLastName, $varBirthday)
{
$this-&gt;lastName = $varLastName;
$this-&gt;birthday = $varBirthday;
}

// Ham nhan gia tri cua firstName (Ho)
public function setFirstName($varFirstName) {
$this-&gt;firstName = $varFirstName;
}

// Ham nhan gia tri cua sex (gioi tinh)
public function setSex($varSex) {
$this-&gt;sex = $varSex;
}

// Ham nhan gia tri cua email
public function setEmail($varEmail) {
$this-&gt;email = $varEmail;
}

// Ham nhan gia tri cua phone
public function setPhone($varPhone) {
$this-&gt;phone = $varPhone;
}

// Ham nhan gia tri cua experienced
public function setExperienced($varExperienced) {
$this-&gt;experienced = $varExperienced;
}

// Ham nhan gia tri cua experienced
public function setAdvantage($varAdvantage) {
$this-&gt;advantage = $varAdvantage;
}

// Ham nhan gia tri cua weakness
public function setWeakness($varWeakness) {
$this-&gt;weakness = $varWeakness;
}

// Ham nhan gia tri cua skill
public function setSkill($varSkill) {
$this-&gt;skill = $varSkill;
}

// In thông tin member
public function printInfo(){
$info = '&lt;b&gt;Thong tin lap trinh vien:&lt;/b&gt;';
$info .= '&lt;br&gt;&lt;b&gt;============================&lt;/b&gt;';
$info .= '&lt;br&gt;&lt;b&gt;Ho:&lt;/b&gt; ' . $this-&gt;firstName;
$info .= '&lt;br&gt;&lt;b&gt;Ten:&lt;/b&gt; ' . $this-&gt;lastName;
$info .= '&lt;br&gt;&lt;b&gt;Ngay sinh:&lt;/b&gt; ' . $this-&gt;birthday;
$info .= '&lt;br&gt;&lt;b&gt;Gioi tinh:&lt;/b&gt; ' . $this-&gt;sex;
$info .= '&lt;br&gt;&lt;b&gt;Email:&lt;/b&gt; ' . $this-&gt;email;
$info .= '&lt;br&gt;&lt;b&gt;Phone:&lt;/b&gt; ' . $this-&gt;phone;
$info .= '&lt;br&gt;&lt;b&gt;Kinh nghiem:&lt;/b&gt; ' . $this-&gt;experienced;
$info .= '&lt;br&gt;&lt;b&gt;Uu diem:&lt;/b&gt; ' . $this-&gt;advantage;
$info .= '&lt;br&gt;&lt;b&gt;Nhuoc diem:&lt;/b&gt; ' . $this-&gt;weakness;
$info .= '&lt;br&gt;&lt;b&gt;Ky nang:&lt;/b&gt; ' . $this-&gt;skill;

return $info;
}

?&gt;
</pre>
<div class="code-area">
<p class="note">//oop.php</p>
</div>
<div class="code-area">
<pre class="brush: php;">&lt;/div&gt;
&lt;div class=&quot;code-area&quot;&gt;&lt;?php
/**
* Zend Framework
*
* @category Training
* @package Zend Framework Basic
* @copyright Copyright (c) 2008 Zend Vietnamese Team (http://www.zend.vn)
* @version $Id: oop.php 2008-02-10 01:35:30Z
* @author Marsu (ZVN Founder team)
*@email zendvn@yahoo.com OR marsu@zend.vn
*
*/&lt;/div&gt;
&lt;div class=&quot;code-area&quot;&gt;

// Nhung file class.programer.php vao trang
include('class.programer.php');

// Goi doi tuong Programer
$objProgramer = new Programer('Hoang','14-02-1985');

// Dua gia tri vao cho thuoc tinh $firstName trong Programer class
$objProgramer-&gt;setFirstName('Nguyen Van');

// Dua gia tri vao cho thuoc tinh $sex trong Programer class
$objProgramer-&gt;setSex('Khong xac dinh');

// Dua gia tri vao cho thuoc tinh $email trong Programer class
$objProgramer-&gt;setEmail('hoang@zend.vn');

// Dua gia tri vao cho thuoc tinh $phone trong Programer class
$objProgramer-&gt;setPhone('0908.115.113');

// Dua gia tri vao cho thuoc tinh $phone trong Programer class
$objProgramer-&gt;setPhone('0908.115.113');

// Dua gia tri vao cho thuoc tinh $experienced trong Programer class
$objProgramer-&gt;setExperienced('3 nam voi ........ Vo Lam Truyen Ky');

// Dua gia tri vao cho thuoc tinh $advantage trong Programer class
$objProgramer-&gt;setAdvantage('nha^.u khong doi thu');

// Dua gia tri vao cho thuoc tinh $weakness trong Programer class
$objProgramer-&gt;setWeakness('nha^.u xong, hay om cot den');

// Dua gia tri vao cho thuoc tinh $weakness trong Programer class
$objProgramer-&gt;setWeakness('nha^.u say, hay om cot den');

// Dua gia tri vao cho thuoc tinh $skill trong Programer class
$objProgramer-&gt;setSkill('sai dau danh do');

// In ra thong tin cua lap trinh vien
echo $objProgramer-&gt;printInfo();

?&gt;
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2009/07/03/js-object-array/" rel="bookmark">[JS Object] Array</a></li><li><a href="http://blog.thuongtin.net/2009/07/03/js-object-math/" rel="bookmark">[ JS Object ] Math</a></li><li><a href="http://blog.thuongtin.net/2009/04/21/cach-su-dung-lenh-dung-lo/" rel="bookmark">Cách sử dụng lệnh dừng lỗ</a></li><li><a href="http://blog.thuongtin.net/2008/10/24/de-lap-trinh-vien-tam-ca-ngay/" rel="bookmark">Để lập trình viên tắm cả ngày</a></li><li><a href="http://blog.thuongtin.net/2008/10/10/js-regexp/" rel="bookmark">JS RegExp</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=289&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/03/lap-trinh-huong-doi-tuong-can-ban/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Class Grab Yahoo</title>
		<link>http://blog.thuongtin.net/2008/10/24/class-grab-yahoo/</link>
		<comments>http://blog.thuongtin.net/2008/10/24/class-grab-yahoo/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 06:57:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Get links]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[grab]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=225</guid>
		<description><![CDATA[Đây là class đăng nhập vào Yahoo và lấy  sổ địa chỉ, list messenger , số mail chưa đọc, lịch.
Demo

Download
Related Posts:Các trang web cho nén javascriptHàm check Page Rank của googleMột số Flugin của JQuery trang trí cho formjQuery: Khả năng liên kết thành chuỗi (một phép thuật jQuery)AutoCompleter Tutorial - jQuery(Ajax)/PHP/My]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Đây là class đăng nhập vào Yahoo và lấy  sổ địa chỉ, list messenger , số mail chưa đọc, lịch.</p>
<p><a class="alignleft" href="http://resource.bdwebwork.com/GrabYahoo/login.html" target="_blank">Demo</a></p>
<p><a href="http://thuongtin.net/code/grabyahoo.zip" target="_blank"><br />
Download</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/11/13/cac-trang-web-cho-nen-javascript/" rel="bookmark">Các trang web cho nén javascript</a></li><li><a href="http://blog.thuongtin.net/2008/10/22/ham-check-page-rank-cua-google/" rel="bookmark">Hàm check Page Rank của google</a></li><li><a href="http://blog.thuongtin.net/2008/11/04/mot-so-flugin-cua-jquery-trang-tri-cho-form/" rel="bookmark">Một số Flugin của JQuery trang trí cho form</a></li><li><a href="http://blog.thuongtin.net/2008/10/10/jquery-kha-nang-lien-ket-thanh-chuoi-mot-phep-thuat-jquery/" rel="bookmark">jQuery: Khả năng liên kết thành chuỗi (một phép thuật jQuery)</a></li><li><a href="http://blog.thuongtin.net/2008/10/20/autocompleter-tutorial-jqueryajaxphpmysql/" rel="bookmark">AutoCompleter Tutorial - jQuery(Ajax)/PHP/MySQL</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=225&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/10/24/class-grab-yahoo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Yahoo Messenger API</title>
		<link>http://blog.thuongtin.net/2008/10/22/yahoo-messenger-api/</link>
		<comments>http://blog.thuongtin.net/2008/10/22/yahoo-messenger-api/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 08:00:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Get links]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[wap]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=218</guid>
		<description><![CDATA[Đây là class login vào yahoo, set status và gửi tin nhắn cho 1 nick. Tôi sưu tầm trên mạng mà giờ chẳng biết bài viết gốc nó nằm mô rồi. Hix!

&#60;?
// Class 'Yahoo Messenger API' v1.0
// details : send pm to any yahoo messenger IDs via PHP
// (c) Hadi Fanaee , Iran , Mashhad ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Đây là class login vào yahoo, set status và gửi tin nhắn cho 1 nick. Tôi sưu tầm trên mạng mà giờ chẳng biết bài viết gốc nó nằm mô rồi. Hix!<br />
<span id="more-218"></span>
<pre class="brush: php;">&lt;?
// Class 'Yahoo Messenger API' v1.0
// details : send pm to any yahoo messenger IDs via PHP
// (c) Hadi Fanaee , Iran , Mashhad , Kasbarg Information Technology .
// Released under the terms of the GNU Public License
// Website : www.php45.com
// Email : info@php45.com

class Ymess {

//-------------------------------------PACKETS----------------------------------------------------
Function Packet1($MyWAPHost)
{
$StrPck = &quot;GET / HTTP/1.1\n&quot;;
$StrPck.=&quot;Referer: /\n&quot;;
$StrPck.=&quot;Accept-Language: en-us\n&quot;;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot;;
$StrPck.=&quot;Host: $MyWAPHost\n\n&quot;;
return $StrPck;
}
Function Packet2($MySID,$MyWAPHost,$MyIntl,$MyCookie)
{

$StrPck = &quot;GET /p/messenger?$MySID HTTP/1.1\n&quot;;
$StrPck.=&quot;Referer: /\n&quot;;
$StrPck.=&quot;Accept-Language: en-us\n&quot;;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot;;
$StrPck.=&quot;Host: $MyWAPHost\n&quot;    ;
$StrPck.=&quot;Cookie: $MyIntl$MyCookie\n\n&quot;;
return $StrPck;
}
Function Packet3($MyWAPHost,$MyIntl,$MyCookie)
{
$StrPck = &quot;GET /p/messenger HTTP/1.1\n&quot;;
$StrPck.=&quot;Referer: /\n&quot;;
$StrPck.=&quot;Accept-Language: en-us\n&quot;   ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot; ;
$StrPck.=&quot;Host: $MyWAPHost\n&quot;        ;
$StrPck.=&quot;Cookie: $MyIntl$MyCookie\n\n&quot;           ;
return  $StrPck;
}
Function Packet4($MyWID,$MyWAPHost,$MyCookie)
{
$StrPck = &quot;GET /p/messenger/welcome?r=$MyWID HTTP/1.1\n&quot;  ;
$StrPck.=&quot;Referer: /\n&quot;;
$StrPck.=&quot;Accept-Language: en-us\n&quot;     ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot; ;
$StrPck.=&quot;Host: $MyWAPHost\n&quot;       ;
$StrPck.=&quot;Cookie: $MyCookie\n\n&quot; ;
return $StrPck;
}

Function Packet5($MyCID,$MyWID,$MySID,$MyWAPHost,$MyIntl,$MyCookie)
{
$StrPck = &quot;POST /p/messenger?c=$MyCID&amp;r=$MyWID&amp;ySiD=$MySID HTTP/1.1\n&quot;  ;
$StrPck.=&quot;Referer: /\n&quot;  ;
$StrPck.=&quot;Accept-Language: en-us\n&quot;  ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot;  ;
$StrPck.=&quot;Host: $MyWAPHost\n&quot;     ;
$StrPck.=&quot;Cookie: $MyIntl$MyCookie\n\n&quot;    ;
return $StrPck;
}

Function Packet6($MyWID,$MyWAPHost,$MyIntl,$MyCookie)
{
$StrPck = &quot;GET /p/logout?r=$MyWID HTTP/1.1\n&quot;   ;
$StrPck.=&quot;Referer: /p/messenger?r=$MyWID\n&quot;  ;
$StrPck.=&quot;Accept-Language: en-us\n&quot;   ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot;  ;
$StrPck.=&quot;Host: $MyWAPHost\n&quot;         ;
$StrPck.=&quot;Cookie: $MyIntl$MyCookie\n\n&quot; ;
return $StrPck;
}

Function Packet7($MyMsg,$MyVictim,$MyCID,$MyWID,$MyIntl,$MyWAPHost,$MyCookie)
{
$mess= substr($MyMsg, 0, 940);
$Pck = &quot;message=$mess&amp;wmlfix=Send&quot;      ;
$lenmess=strlen($Pck);
$StrPck = &quot;POST /p/messenger/chat/$MyVictim/sendIm?c=$MyCID&amp;r=$MyWID HTTP/1.1\n&quot; ;
$StrPck.=&quot;Referer: /p/messenger/chat/$MyVictim?c=$MyCID&amp;r=$MyWID\n&quot;  ;
$StrPck.=&quot;Accept-Language: en-us\n&quot;                  ;
$StrPck.=&quot;Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\n&quot;   ;
$StrPck.=&quot;Content-Type: application/x-www-form-urlencoded\n&quot;     ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot;  ;
$StrPck.=&quot;Host: $MyWAPHost\n&quot;              ;
$StrPck.=&quot;Content-Length: $lenmess\n&quot;     ;
$StrPck.=&quot;Connection: Keep-Alive\n&quot;      ;
$StrPck.=&quot;Cache-Control: no-cache\n&quot;     ;
$StrPck.=&quot;Cookie: $MyIntl$MyCookie\n\n$Pck&quot;  ;
return $StrPck;
}

Function Packet8($MyYID,$MyPw,$MyCookieHost)
{
$StrPck=&quot;&quot;;
$StrPck.=&quot;GET /config/login?login=$MyYID&amp;passwd=$MyPw HTTP/1.1\n&quot;;
$StrPck.=&quot;Referer: /config/login?\n&quot;         ;
$StrPck.=&quot;Accept-Language: en-us\n&quot;  ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot;     ;
$StrPck.=&quot;Host:$MyCookieHost\n&quot;  ;
$StrPck.=&quot;Accept: text/html\n\n&quot; ;
return $StrPck;
}

Function Packet9()
{
$Pck = &quot;user=&quot; &amp; $MyVictim &amp; &quot;&amp;buddyGroup=Friends&amp;message=&quot; &amp; substr($MyMsg, 1, 940) &amp; &quot;&amp;wmlfix=Add&quot;   ;
$StrPck = &quot;POST /p/messenger/contacts/addComplete?c=&quot; &amp; $MyCID &amp; &quot;&amp;r=&quot; &amp; $MyWID &amp; &quot; HTTP/1.1&quot; &amp; &quot;\n&quot;  ;
$StrPck.=&quot;Referer: /p/messenger/contacts/add?c=&quot; &amp; $MyCID &amp; &quot;&amp;r=&quot; &amp; $MyWID &amp; &quot;\n&quot;    ;
$StrPck.=&quot;Accept-Language: en-us&quot; &amp; &quot;\n&quot;                          ;
$StrPck.=&quot;Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*&quot; &amp; &quot;\n&quot;  ;
$StrPck.=&quot;Content-Type: application/x-www-form-urlencoded&quot; &amp; &quot;\n&quot;                                        ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)&quot; &amp; &quot;\n&quot;   ;
$StrPck.=&quot;Host: &quot; &amp; $MyWAPHost &amp; &quot;\n&quot;                      ;
$StrPck.=&quot;Content-Length: &quot; &amp; strlen($Pck) &amp; &quot;\n&quot;         ;
$StrPck.=&quot;Connection: Keep-Alive&quot; &amp; &quot;\n&quot;               ;
$StrPck.=&quot;Cache-Control: no-cache&quot; &amp; &quot;\n&quot;            ;
$StrPck.=&quot;Cookie: &quot; &amp; $MyIntl &amp; $MyCookie &amp; &quot;\n&quot; &amp; &quot;\n&quot; &amp; $Pck       ;
return $StrPck;
}

Function Packet12($MyCID,$MyWID,$MyIntl,$MyWAPHost,$MyCookie,$MySID)
{
//http://wap.yahoo.com/p/messenger/contacts/recent?g=Friends&amp;c=Xn8TUwVHetB&amp;r=1620424127&amp;ySiD=oCChSJj.2f9bJBbg7Vy9
$StrPck = &quot;GET /p/messenger/contacts/recent?g=Friend&amp;c=$MyCID&amp;r=$MyWID&amp;ySiD=$MySID HTTP/1.1\n&quot;  ;
$StrPck.=&quot;Referer: /\n&quot;      ;
$StrPck.=&quot;Accept-Language: en-us\n&quot;            ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot;    ;
$StrPck.=&quot;Host: $MyWAPHost\n&quot;    ;
$StrPck.=&quot;Cookie: $MyIntl$MyCookie\n\n&quot;    ;
return $StrPck;
}
Function Packet10()
{
$StrPck = &quot;GET /p/messenger/contacts/deny?yid=&quot; &amp; $MyVictim &amp; &quot;&amp;c=&quot; &amp; $MyCID &amp; &quot;&amp;r=&quot; &amp; $MyWID &amp; &quot; HTTP/1.1&quot; &amp; &quot;\n&quot;  ;
$StrPck.=&quot;Referer: /p/messenger/notify?yid=&quot; &amp; $MyVictim &amp; &quot;&amp;c=&quot; &amp; $MyCID &amp; &quot;&amp;r=&quot; &amp; $MyWID &amp; &quot;\n&quot;      ;
$StrPck.=&quot;Accept-Language: en-us&quot; &amp; &quot;\n&quot;            ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)&quot; &amp; &quot;\n&quot;    ;
$StrPck.=&quot;Host: &quot; &amp; $MyWAPHost &amp; &quot;\n&quot;    ;
$StrPck.=&quot;Cookie: &quot; &amp; $MyIntl &amp; $MyCookie &amp; &quot;\n&quot; &amp; &quot;\n&quot;    ;
return $StrPck;
}
Function Packet11($MyMsg,$MyCID,$MyWID,$MyIntl,$MyWAPHost,$MyCookie)
{
$mess= substr($MyMsg, 0, 250);

$Pck = &quot;message=$mess&amp;wmlfix=Submit&quot;    ;
$lenmess=strlen($Pck);
$StrPck = &quot;POST /p/messenger/prefs/status/submit?c=$MyCID&amp;r=$MyWID HTTP/1.1\n&quot;  ;
$StrPck.=&quot;Referer: /p/messenger/prefs/status?c=$MyCID&amp;r=$MyWID\n&quot;      ;
$StrPck.=&quot;Accept-Language: en-us\n&quot;                     ;
$StrPck.=&quot;Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\n&quot;    ;
$StrPck.=&quot;Content-Type: application/x-www-form-urlencoded\n&quot;                                                ;
$StrPck.=&quot;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\n&quot;         ;
$StrPck.=&quot;Host: $MyWAPHost\n&quot;                                                                              ;
$StrPck.=&quot;Content-Length: $lenmess\n&quot;                                                                  ;
$StrPck.=&quot;Connection: Keep-Alive\n&quot;                                                                           ;
$StrPck.=&quot;Cache-Control: no-cache\n&quot;                                                                          ;
$StrPck.=&quot;Cookie: $MyIntl$MyCookie\n\n$Pck&quot;                                                    ;
return $StrPck;
}
//-------------------------------------PACKETS----------------------------------------------------
//--------------------------------------------------------------------------------------
function Connect($pServer,$hPort){
$hStream = fsockopen($pServer, $hPort);
if(!$hStream){$IsConnect=0;echo &quot;Cannot connect to $pServer at port $hPort&quot;; exit;}
$IsConnect=1;
return array($IsConnect,$hStream);
}
//--------------------------------------------------------------------------------------
function Disconnect($hStream){
fclose($hStream);
}
//--------------------------------------------------------------------------------------
function GetDataArrival ($hStream){
//  $hResult = '';
while(!feof($hStream)) {
// receive the results of the request
$hResulttmp.= fgets($hStream);
}
$hResult=html_entity_decode($hResulttmp);
return  $hResult;
}
//--------------------------------------------------------------------------------------
function SendData($hStream,$Data){
fputs($hStream, $Data);
}
//--------------------------------------------------------------------------------------
function LoginWap ($myID,$myPass,$CookieHost,$wapHost,$Status,$VictimID,$Message){
$logged=0;
list($Connected5,$stream5) = $this-&gt;Connect($CookieHost, 80);

if ($Connected5=1){
$this-&gt;SendData($stream5 , $this-&gt;Packet8($myID,$myPass,$CookieHost));
$res5 = $this-&gt;GetDataArrival($stream5);
if ($res5 &lt;&gt; ''){
//GET COOKIE
$cookie1 = $this-&gt;GetCode(&quot;Y=v=&quot;,&quot;;&quot;,$res5);
$cookie2 = $this-&gt;GetCode(&quot;T=z=&quot;,&quot;;&quot;,$res5);
//if($cookie1=&quot;&quot; OR $cookie2=&quot;&quot;){echo &quot;CONNECT FAILED! SERVER IS BUSY OR INVALID ID/PASS. TRY AGAIN LATER.&quot;;}
$cookie =  &quot;Y=v=$cookie1; T=z=$cookie2&quot;;
}
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
list($Connected,$stream) = $this-&gt;Connect($wapHost, 80);

if ($Connected=1){
$this-&gt;SendData($stream , $this-&gt;Packet1($wapHost));
$res = $this-&gt;GetDataArrival($stream);
if ($res &lt;&gt; ''){
//GET SID AND INTL
$sid = $this-&gt;GetCode(&quot;ySiD=&quot;,'&quot;',$res);
$intltmp = $this-&gt;GetCode(&quot;B=&quot;,&quot;;&quot;,$res);
$intl= &quot;B=$intltmp;&quot; ;
}
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
list($Connected1,$stream1) = $this-&gt;Connect($wapHost, 80);

if ($Connected1=1){
$this-&gt;SendData($stream1 , $this-&gt;Packet2($sid,$wapHost,$intl,$cookie));
$res1 = $this-&gt;GetDataArrival($stream1);
if ($res1 &lt;&gt; ''){
//ENTER SID AND INTL
}
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
list($Connected2,$stream2) = $this-&gt;Connect($wapHost, 80);

if ($Connected2=1){
$this-&gt;SendData($stream2 , $this-&gt;Packet3($wapHost,$intl,$cookie));
$res2 = $this-&gt;GetDataArrival($stream2);
if ($res2 &lt;&gt; ''){
//GET WID
$widtmp = $this-&gt;GetCode(&quot;welcome?r=&quot;,&quot;C&quot;,$res2);
$wid = substr($widtmp,0,strlen($widtmp)-2);
// $Dat5 = explode(&quot;welcome?r=&quot;,$res2);
//$Dat6 = explode($res2,$Dat5[1]);
//$wid = $Dat6[0];
}
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
list($Connected3,$stream3) = $this-&gt;Connect($wapHost, 80);

if ($Connected3=1){
$this-&gt;SendData($stream3 , $this-&gt;Packet4($wid,$wapHost,$cookie));
$res3 = $this-&gt;GetDataArrival($stream3);
if ($res3 &lt;&gt; ''){
//GET CID
$cid = $this-&gt;GetCode(&quot;?c=&quot;,&quot;&amp;r=&quot;,$res3);
}
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
list($Connected4,$stream4) = $this-&gt;Connect($wapHost, 80);

if ($Connected4=1){
$this-&gt;SendData($stream4 , $this-&gt;Packet5($cid,$wid,$sid,$wapHost,$intl,$cookie));
$res4 = $this-&gt;GetDataArrival($stream4);
if ($res4 &lt;&gt; ''){
//FINNALLY CONNECT
//echo &quot;COOKIE:$cookie ______________SID:$sid ______________WID:$wid ______________CID:$cid ______________INTL:$intl&quot; ;
$logged=1;
}
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
$num = rand(0,10000);
sleep(1);
$this-&gt;SetStatus($Status,$cid,$wid,$intl,$wapHost,$cookie);
//$this-&gt;LogoutWap($wid, $wapHost,$intl ,$cookie);

//sleep(1);
//$mess1 = $this-&gt;Test($cid,$wid,$intl,$wapHost,$cookie,$sid);
//sleep(1);
$this-&gt;SendMessage($Message,$VictimID,$cid,$wid,$intl,$wapHost,$cookie);
//sleep(1);
$logged=1;
//sleep(1); exit;
return array($cid,$wid,$sid,$intl,$cookie,$wapHost,$logged);

}
//--------------------------------------------------------------------------------------
function LogoutWap($MyWID,$MyWAPHost,$MyIntl,$MyCookie){
list($Connected,$stream) = $this-&gt;Connect($MyWAPHost, 80);

if ($Connected=1){
$this-&gt;SendData($stream , $this-&gt;Packet6($MyWID,$MyWAPHost,$MyIntl,$MyCookie));
$res = $this-&gt;GetDataArrival($stream);
if ($res &lt;&gt; ''){
//LOGOUT
echo $this-&gt;Packet6($MyWID,$MyWAPHost,$MyIntl,$MyCookie);
}
}
}
//--------------------------------------------------------------------------------------
function SendMessage($MyMsg,$MyVictim,$MyCID,$MyWID,$MyIntl,$MyWAPHost,$MyCookie){
list($Connected,$stream) = $this-&gt;Connect($MyWAPHost, 80);

if ($Connected=1){
$this-&gt;SendData($stream , $this-&gt;Packet7($MyMsg,$MyVictim,$MyCID,$MyWID,$MyIntl,$MyWAPHost,$MyCookie));
$res = $this-&gt;GetDataArrival($stream);
if ($res &lt;&gt; ''){
//LOGOUT
//echo $this-&gt;Packet6($MyWID,$MyWAPHost,$MyIntl,$MyCookie);
}
}
}
//--------------------------------------------------------------------------------------
/*function Test($MyCID,$MyWID,$MyIntl,$MyWAPHost,$MyCookie,$MySID){
list($Connected,$stream) = $this-&gt;Connect($MyWAPHost, 80);

if ($Connected=1){
$this-&gt;SendData($stream , $this-&gt;Packet12($MyCID,$MyWID,$MyIntl,$MyWAPHost,$MyCookie,$MySID));
$res = $this-&gt;GetDataArrival($stream);
if ($res &lt;&gt; ''){
//LOGOUT
echo $res;
}
}
return $res;
}   */
//--------------------------------------------------------------------------------------
function SetStatus($MyMess,$MyCID,$MyWID,$MyIntl,$MyWAPHost,$MyCookie){
list($Connected,$stream) = $this-&gt;Connect($MyWAPHost, 80);

if ($Connected=1){
$this-&gt;SendData($stream , $this-&gt;Packet11($MyMess,$MyCID,$MyWID,$MyIntl,$MyWAPHost,$MyCookie));
$res = $this-&gt;GetDataArrival($stream);
if ($res &lt;&gt; ''){
//
}
}
//return 0;
}
//--------------------------------------------------------------------------------------

function GetCode($start,$end,$str){

$x1=strpos($str,$start);
if($x1){
$x2=strpos($str,$end , $x1+1);
$getbet=substr($str,$x1+strlen($start),$x2-$x1-strlen($start));
}else{
$getbet=&quot;&quot;;
}
return $getbet;
}
}
?&gt;
</pre>
<p>Lưu file lại với tên là yim.php</p>
<p>Tạo 1 file để test với nội dung:</p>
<pre class="brush: php;">
&lt;?php
include(&quot;yim.php&quot;);
$ym=new Ymess();
$mess = &quot;:))&quot;;
list($MyCid,$MyWid,$MySid,$MyIntl,$MyCookie,$MyWapHost,$logged)=$ym-&gt;LoginWap(&quot;Nick&quot;,&quot;Pass&quot;,'login.yahoo.com','us.m.yahoo.com',&quot;Status&quot;,&quot;Victim&quot;,&quot;Nội dung tin nhắn&quot;);
?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2009/04/29/autoit-viet-phan-mem-spam-web/" rel="bookmark">[AutoIt] Viết phần mềm spam web</a></li><li><a href="http://blog.thuongtin.net/2008/09/10/class-curl/" rel="bookmark">Class Curl</a></li><li><a href="http://blog.thuongtin.net/2008/09/11/ham-kiem-tra-file-size/" rel="bookmark">Hàm kiểm tra file size</a></li><li><a href="http://blog.thuongtin.net/2009/05/03/autoit-source-tool-flood-co-gui/" rel="bookmark">[AutoIt] Source tool Flood có GUI</a></li><li><a href="http://blog.thuongtin.net/2008/10/22/doan-ma-http-ddos-attack-bkavcomvn/" rel="bookmark">Đoạn mã HTTP DDOS attack bkav.com.vn</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=218&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/10/22/yahoo-messenger-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Các biện pháp chống chôm link ảnh</title>
		<link>http://blog.thuongtin.net/2008/10/22/cac-bien-phap-chong-chom-link-anh/</link>
		<comments>http://blog.thuongtin.net/2008/10/22/cac-bien-phap-chong-chom-link-anh/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 04:02:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hack - Security]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[bảo mật]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=207</guid>
		<description><![CDATA[Cách 1:
Xài file htaccess:

&#60;IfModule mod_rewrite.c&#62;
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_USER_AGENT} !(googlebot-image&#124;msnbot&#124;psbot&#124;yahoo-mmcrawler) [NC]
RewriteRule \.(bmp&#124;gif&#124;jpe?g&#124;png)$ - [NC,F]
&#60;/IfModule&#62;

Với cách này thì khi site nào chôm link ảnh sẽ không thấy được ảnh 
Cách 2:
Cũng xài htaccess:

&#60;IfModule mod_rewrite.c&#62;
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_USER_AGENT} !(googlebot-image&#124;msnbot&#124;psbot&#124;yahoo-mmcrawler) [NC]
RewriteCond %{REQUEST_URI} !^/hotlink\.png$
RewriteRule \.(bmp&#124;gif&#124;jpe?g&#124;png)$ /hotlink.png [L]
&#60;/IfModule&#62;

Với cách này thì site nào chôm link ảnh sẽ ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Cách 1:<br />
Xài file htaccess:</p>
<pre class="brush: php;">
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_USER_AGENT} !(googlebot-image|msnbot|psbot|yahoo-mmcrawler) [NC]
RewriteRule \.(bmp|gif|jpe?g|png)$ - [NC,F]
&lt;/IfModule&gt;
</pre>
<p>Với cách này thì khi site nào chôm link ảnh sẽ không thấy được ảnh <img class="inlineimg" title="Big grin" src="http://forum.tvphp.net/images/smilies/yahoo/004.gif" border="0" alt="" /></p>
<p>Cách 2:<br />
Cũng xài htaccess:</p>
<pre class="brush: php;">
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_USER_AGENT} !(googlebot-image|msnbot|psbot|yahoo-mmcrawler) [NC]
RewriteCond %{REQUEST_URI} !^/hotlink\.png$
RewriteRule \.(bmp|gif|jpe?g|png)$ /hotlink.png [L]
&lt;/IfModule&gt;
</pre>
<p>Với cách này thì site nào chôm link ảnh sẽ thấy cái ảnh hotlink.png đó (kiểu này giống 24h )</p>
<p>Cách 3:<br />
Xài htaccess kèm kỹ thuật Digital Watermarking (<a rel="nofollow" href="http://en.wikipedia.org/wiki/Digital_watermarking" target="_blank">http://en.wikipedia.org/wiki/Digital_watermarking</a>)</p>
<p>Tạo file htaccess:</p>
<pre class="brush: php;">
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_USER_AGENT} !(googlebot-image|msnbot|psbot|yahoo-mmcrawler) [NC]
RewriteRule (^.*\.(bmp|gif|jpe?g|png)$) /watermark.php?src=$1 [L]
&lt;/IfModule&gt;
</pre>
<p>và đây là file watermark.php</p>
<pre class="brush: php;">&lt;?php

header('content-type: image/jpeg');

$image = imagecreatefromjpeg($_GET['src']);

$watermark = imagecreatefrompng('watermark.png');

$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);

$dest_x = imagesx($image) - $watermark_width;
$dest_y = imagesy($image) - $watermark_height;

imagecopymerge($image, $watermark, $dest_x - 5, 5, 0, 0, $watermark_width, $watermark_height, 80);

imagejpeg($image, NULL, 85);

imagedestroy($image);
imagedestroy($watermark);

?&gt;
</pre>
<p>(Sưu tầm)</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/09/13/image-information/" rel="bookmark">image information</a></li><li><a href="http://blog.thuongtin.net/2008/09/13/chuyen-hinh-anh-thanh-ky-tu-ascii/" rel="bookmark">Chuyển hình ảnh thành ký tự ASCII</a></li><li><a href="http://blog.thuongtin.net/2008/10/07/image-to-ascii/" rel="bookmark">image to ascii</a></li><li><a href="http://blog.thuongtin.net/2009/04/06/affiliate-va-mot-thu-thuat-kiem-clicks/" rel="bookmark">Affiliate và một thủ thuật kiếm Clicks</a></li><li><a href="http://blog.thuongtin.net/2009/04/06/3-cach-ep-phai-click-vao-link-aff-khi-vao-chinh-site-aff-cua-minh/" rel="bookmark">3 Cách ép phải click vào link aff khi vào chính site aff của mình.</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=207&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/10/22/cac-bien-phap-chong-chom-link-anh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Class: Unzip files</title>
		<link>http://blog.thuongtin.net/2008/09/13/php-class-unzip-files/</link>
		<comments>http://blog.thuongtin.net/2008/09/13/php-class-unzip-files/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 03:13:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=99</guid>
		<description><![CDATA[

&#60;?php
/**************************************
seesaw associates &#124; http://seesaw.net

client:
file:
description:

Copyright (C) 2008 Matt Kenefick(.com)
**************************************/

class zipArch {
/**
* Unzip the source_file in the destination dir
*
* @param   string      The path to the ZIP-file.
* @param   string      The path where the zipfile should be unpacked, if false the directory of the zip-file ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">
<pre class="brush: php;">
&lt;?php
/**************************************
seesaw associates | http://seesaw.net

client:
file:
description:

Copyright (C) 2008 Matt Kenefick(.com)
**************************************/

class zipArch {
/**
* Unzip the source_file in the destination dir
*
* @param   string      The path to the ZIP-file.
* @param   string      The path where the zipfile should be unpacked, if false the directory of the zip-file is used
* @param   boolean     Indicates if the files will be unpacked in a directory with the name of the zip-file (true) or not (false) (only if the destination directory is set to false!)
* @param   boolean     Overwrite existing files (true) or not (false)
*
* @return  boolean     Succesful or not
*/
function unzip($src_file, $dest_dir=false, $create_zip_name_dir=true, $overwrite=true)
{
if(function_exists(&quot;zip_open&quot;))
{
if(!is_resource(zip_open($src_file)))
{
$src_file=dirname($_SERVER['SCRIPT_FILENAME']).&quot;/&quot;.$src_file;
}

if (is_resource($zip = zip_open($src_file)))
{
$splitter = ($create_zip_name_dir === true) ? &quot;.&quot; : &quot;/&quot;;
if ($dest_dir === false) $dest_dir = substr($src_file, 0, strrpos($src_file, $splitter)).&quot;/&quot;;

// Create the directories to the destination dir if they don't already exist
$this-&gt;create_dirs($dest_dir);

// For every file in the zip-packet
while ($zip_entry = zip_read($zip))
{
// Now we're going to create the directories in the destination directories

// If the file is not in the root dir
$pos_last_slash = strrpos(zip_entry_name($zip_entry), &quot;/&quot;);
if ($pos_last_slash !== false)
{
// Create the directory where the zip-entry should be saved (with a &quot;/&quot; at the end)
$this-&gt;create_dirs($dest_dir.substr(zip_entry_name($zip_entry), 0, $pos_last_slash+1));
}

// Open the entry
if (zip_entry_open($zip,$zip_entry,&quot;r&quot;))
{

// The name of the file to save on the disk
$file_name = $dest_dir.zip_entry_name($zip_entry);

// Check if the files should be overwritten or not
if ($overwrite === true || $overwrite === false &amp;&amp; !is_file($file_name))
{
// Get the content of the zip entry
$fstream = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

if(!is_dir($file_name))
file_put_contents($file_name, $fstream );
// Set the rights
if(file_exists($file_name))
{
chmod($file_name, 0777);
echo &quot;&lt;span style=&quot;color:#1da319;&quot;&gt;file saved: &lt;/span&gt;&quot;.$file_name.&quot;&lt;br /&gt;&quot;;
}
else
{
echo &quot;&lt;span style=&quot;color:red;&quot;&gt;file not found: &lt;/span&gt;&quot;.$file_name.&quot;&lt;br /&gt;&quot;;
}
}

// Close the entry
zip_entry_close($zip_entry);
}
}
// Close the zip-file
zip_close($zip);
}
else
{
echo &quot;No Zip Archive Found.&quot;;
return false;
}

return true;
}
else
{
if(version_compare(phpversion(), &quot;5.2.0&quot;, &quot;&lt;&quot;))
$infoVersion=&quot;(use PHP 5.2.0 or later)&quot;;

echo &quot;You need to install/enable the php_zip.dll extension $infoVersion&quot;;
}
}

function create_dirs($path)
{
if (!is_dir($path))
{
$directory_path = &quot;&quot;;
$directories = explode(&quot;/&quot;,$path);
array_pop($directories);

foreach($directories as $directory)
{
$directory_path .= $directory.&quot;/&quot;;
if (!is_dir($directory_path))
{
mkdir($directory_path);
chmod($directory_path, 0777);
}
}
}
}

}
?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/09/12/tao-1-file-download-file/" rel="bookmark">Tạo 1 file download file</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/play-video-youtube-flv-player-cua-ban/" rel="bookmark">Play video youtube = flv player của bạn</a></li><li><a href="http://blog.thuongtin.net/2008/09/13/scan-for-images/" rel="bookmark">Scan for Images</a></li><li><a href="http://blog.thuongtin.net/2008/09/11/ham-kiem-tra-file-size/" rel="bookmark">Hàm kiểm tra file size</a></li><li><a href="http://blog.thuongtin.net/2009/06/29/php-display-server-load/" rel="bookmark">[PHP] Display Server Load</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=99&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/09/13/php-class-unzip-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Class login</title>
		<link>http://blog.thuongtin.net/2008/09/12/class-login/</link>
		<comments>http://blog.thuongtin.net/2008/09/12/class-login/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 08:00:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=75</guid>
		<description><![CDATA[
class Auth
{
var $user_id;
var $username;
var $password;
var $ok;
var $salt = &#34;34asdf34&#34;;
var $domain = &#34;.domain.com&#34;;

function Auth()
{
global $db;

$this-&#62;user_id = 0;
$this-&#62;username = &#34;Guest&#34;;
$this-&#62;ok = false;

if(!$this-&#62;check_session()) $this-&#62;check_cookie();

return $this-&#62;ok;
}

function check_session()
{
if(!empty($_SESSION['auth_username']) &#38;&#38; !empty($_SESSION['auth_password']))
return $this-&#62;check($_SESSION['auth_username'], $_SESSION['auth_password']);
else
return false;
}

function check_cookie()
{
if(!empty($_COOKIE['auth_username']) &#38;&#38; !empty($_COOKIE['auth_password']))
return $this-&#62;check($_COOKIE['auth_username'], $_COOKIE['auth_password']);
else
return false;
}

function login($username, $password)
{
global $db;
$db-&#62;query(&#34;SELECT user_id FROM users WHERE username = '$username' AND password = '$password'&#34;);
if(mysql_num_rows($db-&#62;result) == 1)
{
$this-&#62;user_id = mysql_result($db-&#62;result, 0, 0);
$this-&#62;username = ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">
<pre class="brush: php;">class Auth
{
var $user_id;
var $username;
var $password;
var $ok;
var $salt = &quot;34asdf34&quot;;
var $domain = &quot;.domain.com&quot;;

function Auth()
{
global $db;

$this-&gt;user_id = 0;
$this-&gt;username = &quot;Guest&quot;;
$this-&gt;ok = false;

if(!$this-&gt;check_session()) $this-&gt;check_cookie();

return $this-&gt;ok;
}

function check_session()
{
if(!empty($_SESSION['auth_username']) &amp;&amp; !empty($_SESSION['auth_password']))
return $this-&gt;check($_SESSION['auth_username'], $_SESSION['auth_password']);
else
return false;
}

function check_cookie()
{
if(!empty($_COOKIE['auth_username']) &amp;&amp; !empty($_COOKIE['auth_password']))
return $this-&gt;check($_COOKIE['auth_username'], $_COOKIE['auth_password']);
else
return false;
}

function login($username, $password)
{
global $db;
$db-&gt;query(&quot;SELECT user_id FROM users WHERE username = '$username' AND password = '$password'&quot;);
if(mysql_num_rows($db-&gt;result) == 1)
{
$this-&gt;user_id = mysql_result($db-&gt;result, 0, 0);
$this-&gt;username = $username;
$this-&gt;ok = true;

$_SESSION['auth_username'] = $username;
$_SESSION['auth_password'] = md5($password . $this-&gt;salt);
setcookie(&quot;auth_username&quot;, $username, time()+60*60*24*30, &quot;/&quot;, $this-&gt;domain);
setcookie(&quot;auth_password&quot;, md5($password . $this-&gt;salt), time()+60*60*24*30, &quot;/&quot;, $this-&gt;domain);

return true;
}
return false;
}

function check($username, $password)
{
global $db;
$db-&gt;query(&quot;SELECT user_id, password FROM users WHERE username = '$username'&quot;);
if(mysql_num_rows($db-&gt;result) == 1)
{
$db_password = mysql_result($db-&gt;result, 0, 1);
if(md5($db_password . $this-&gt;salt) == $password)
{
$this-&gt;user_id = mysql_result($db-&gt;result, 0, 0);
$this-&gt;username = $username;
$this-&gt;ok = true;
return true;
}
}
return false;
}

function logout()
{
$this-&gt;user_id = 0;
$this-&gt;username = &quot;Guest&quot;;
$this-&gt;ok = false;

$_SESSION['auth_username'] = &quot;&quot;;
$_SESSION['auth_password'] = &quot;&quot;;

setcookie(&quot;auth_username&quot;, &quot;&quot;, time() - 3600, &quot;/&quot;, $this-&gt;domain);
setcookie(&quot;auth_password&quot;, &quot;&quot;, time() - 3600, &quot;/&quot;, $this-&gt;domain);
}

}
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/11/04/login-and-logout-using-sessions-and-cookies/" rel="bookmark">Login and Logout using Sessions and Cookies</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/file-sao-luu-du-lieu/" rel="bookmark">File sao lưu dữ liệu</a></li><li><a href="http://blog.thuongtin.net/2008/11/18/chuyen-doi-cac-mui-gio/" rel="bookmark">Chuyển đổi các múi giờ</a></li><li><a href="http://blog.thuongtin.net/2008/10/15/lay-noi-dung-cua-1-trang-web-file_get_contents/" rel="bookmark">Lấy nội dung của 1 trang web = file_get_contents</a></li><li><a href="http://blog.thuongtin.net/2008/10/10/chong-view-link-tu-cac-site-xai-xtre/" rel="bookmark">Chống view link từ các site xài xtre</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=75&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/09/12/class-login/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Class Curl</title>
		<link>http://blog.thuongtin.net/2008/09/10/class-curl/</link>
		<comments>http://blog.thuongtin.net/2008/09/10/class-curl/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 03:55:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[curl]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=17</guid>
		<description><![CDATA[

&#60;?
//@class CURL
//@author sans_amour
//@copyright TVPHP.NET
//@date 12/15/2007

class CURL{
var $contents;
var $_header;
var $headers=array();
var $body;
var $url=&#34;&#34;;

function exec($method, $url, $vars=&#34;&#34;,$h=1,$cookie=&#34;&#34;,$referer=&#34;&#34;,$ua=&#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0&#34;) {
$ch = curl_init();
//$ip = rand(0,255).&#34;.&#34;.rand(0,255).&#34;.&#34;.rand(0,255).&#34;.&#34;.rand(0,255);
//$header =array(&#34;REMOTE_ADDR: $ip&#34;);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, ($h==2) ? 0:1);

if($ua) curl_setopt($ch, CURLOPT_USERAGENT, $ua);

if($referer &#124;&#124; $this-&#62;url) curl_setopt($ch, CURLOPT_REFERER,$referer?$referer:$this-&#62;url);

//curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

if(strncmp($url,&#34;https&#34;,6)) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
}
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

if ($method ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">
<pre class="brush: php;">
&lt;?
//@class CURL
//@author sans_amour
//@copyright TVPHP.NET
//@date 12/15/2007

class CURL{
var $contents;
var $_header;
var $headers=array();
var $body;
var $url=&quot;&quot;;

function exec($method, $url, $vars=&quot;&quot;,$h=1,$cookie=&quot;&quot;,$referer=&quot;&quot;,$ua=&quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0&quot;) {
$ch = curl_init();
//$ip = rand(0,255).&quot;.&quot;.rand(0,255).&quot;.&quot;.rand(0,255).&quot;.&quot;.rand(0,255);
//$header =array(&quot;REMOTE_ADDR: $ip&quot;);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, ($h==2) ? 0:1);

if($ua) curl_setopt($ch, CURLOPT_USERAGENT, $ua);

if($referer || $this-&gt;url) curl_setopt($ch, CURLOPT_REFERER,$referer?$referer:$this-&gt;url);

//curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

if(strncmp($url,&quot;https&quot;,6)) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
}
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
$data = curl_exec($ch);

$this-&gt;url=$url;

if ($data) {

if(preg_match(&quot;/^HTTP\/1\.1 302/&quot;,$data) &amp;&amp; $h!=2 &amp;&amp; strstr($data,&quot;\r\n\r\nHTTP/1.1 200&quot;) ){
$pos = strpos($data, &quot;\r\n\r\n&quot;);

$data= substr($data, $pos + 4);
}

if($h==1||$h==2) return $data;
else{

$pos = strpos($data, &quot;\r\n\r\n&quot;);
$this-&gt;body = substr($data, $pos + 4);
$this-&gt;_header = substr($data, 0,$pos);
$this-&gt;_header=explode(&quot;\r\n&quot;,trim($this-&gt;_header));
foreach($this-&gt;_header as $v){
$v=explode(&quot;:&quot;,$v,2);
$this-&gt;headers[$v[0]]=trim($v[1]);
}
return $h==3?$this-&gt;headers:array($this-&gt;headers,$this-&gt;body);
}

} else {
return curl_error($ch);
}
curl_close($ch);
}

function get($url, $vars=&quot;&quot; ,$h=1) {
return $this-&gt;exec('GET', $url, $vars,$h);
}
function post($url, $vars ,$h=1) {
return $this-&gt;exec('POST', $url, $vars,$h);
}
function seturl($url){
$this-&gt;url=$url;
}
function setref($r){

}
}
//$c = new CURL;
//echo $c-&gt;get('http://web.com');
?&gt;
</pre>
<p><code style="white-space: nowrap;"><code><span style="color: #000000;"> </span></code><!-- php buffer end --> </code></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/10/22/get-alexa-rank/" rel="bookmark">Get Alexa Rank</a></li><li><a href="http://blog.thuongtin.net/2008/10/10/ham-tinh-tuoi/" rel="bookmark">Hàm tính tuổi</a></li><li><a href="http://blog.thuongtin.net/2008/09/11/ham-kiem-tra-file-size/" rel="bookmark">Hàm kiểm tra file size</a></li><li><a href="http://blog.thuongtin.net/2008/10/22/yahoo-messenger-api/" rel="bookmark">Yahoo Messenger API</a></li><li><a href="http://blog.thuongtin.net/2008/10/27/query-get-du-lieu-bang-ajax/" rel="bookmark">Query: Get dữ liệu bằng ajax</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=17&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/09/10/class-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Email Class</title>
		<link>http://blog.thuongtin.net/2008/09/10/simple-email-class/</link>
		<comments>http://blog.thuongtin.net/2008/09/10/simple-email-class/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 03:50:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[mail]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=15</guid>
		<description><![CDATA[
&#60;?php
/*
* PHP Email Class
*
* Class to deal with sending emails in PHP
* Makes it easy to send emails in PHP with attachments and such.
*
* Written By Jacob Wyke - jacob@redvodkajelly.com - www.redvodkajelly.com
*
* LICENSE
* ---
* Feel free to use this as you wish, just give me credit where credits due and drop me an email telling ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">
<pre class="brush: php;">&lt;?php
/*
* PHP Email Class
*
* Class to deal with sending emails in PHP
* Makes it easy to send emails in PHP with attachments and such.
*
* Written By Jacob Wyke - jacob@redvodkajelly.com - www.redvodkajelly.com
*
* LICENSE
* ---
* Feel free to use this as you wish, just give me credit where credits due and drop me an email telling me what your using it for so I can check out all the cool ways its been used.
*
* USAGE
* --
*
*   $objEmail = new RVJ_mail();
*
*   $objEmail-&gt;addUser(&quot;jacob@redvodkajelly.com&quot;);
*   $objEmail-&gt;setFrom(&quot;Frozensheep Ltd &lt;admin@frozensheep.com&gt;&quot;);
*   $objEmail-&gt;setHTML();
*   //$objEmail-&gt;setPlain();
*   $objEmail-&gt;setPriority(3);
*   $objEmail-&gt;addReadConfirmationEmail(&quot;admin@frozensheep.com&quot;);
*   $objEmail-&gt;addAttachment(&quot;logo.gif&quot;, ‘logo.gif', ‘image/gif');
*   $objEmail-&gt;addAttachment(&quot;word.doc&quot;, ‘word.doc', ‘application/msword');
*   $objEmail-&gt;addAttachment(&quot;excel.xls&quot;, ‘excel.xls', ‘application/vnd.ms-excel');
*   $objEmail-&gt;setSubject(&quot;Testing new class&quot;);
*   $objEmail-&gt;setContent(&quot;hey &lt;b&gt;dude&lt;/b&gt;&quot;);
*   $objEmail-&gt;send();
*
*/

class RVJ_mail {

var $arrTo = array();
var $arrCC = array();
var $arrBCC = array();
var $strContent = &quot;&quot;;
var $strSubject = &quot;&quot;;
var $arrHeader = array();
var $arrAttachments = array();
var $numPriority = 3;
var $strCharSet = &quot;utf-8&quot;;
var $strContentType = &quot;text/plain&quot;;
var $strEncoding = &quot;8bit&quot;;

/*
*
*   @Method:      addUser
*   @Parameters:   1
*   @Param-1:      strAddress - String - Holds an email address
*   @Description:   Adds a user to send the email to
*
*/
function addUser($strAddress){
if($this-&gt;emailCheck($strAddress)){
$this-&gt;arrTo[] = $strAddress;
return 1;
}else{
return 0;
}
}

/*
*
*   @Method:      removeUser
*   @Parameters:   1
*   @Param-1:      strAddress - String - Holds an email address
*   @Description:   Removes an address from the array
*
*/
function removeUser($strAddress){
//create array or arrays to check
$arrVars = array('arrTo', 'arrCC', 'arrBCC');
foreach($arrVars as $resVars){
//sees if the item exists in the array
$numKey = array_search($strAddress, $this-&gt;{$resVars});
if(isset($numKey)){
//remove the email address
$this-&gt;{$resVars}[$numKey] = &quot;&quot;;
}
unset($numKey);
}
}

/*
*
*   @Method:      addCC
*   @Parameters:   1
*   @Param-1:      strAddress - String - Holds an email address
*   @Description:   Adds a CC user to send to
*
*/
function addCC($strAddress){
if($this-&gt;emailCheck($strAddress)){
$this-&gt;arrCC[] = $strAddress;
return 1;
}else{
return 0;
}
}

/*
*
*   @Method:      addBCC
*   @Parameters:   1
*   @Param-1:      strAddress - String - Holds an email address
*   @Description:   Adds a BCC user to send to
*
*/
function addBCC($strAddress){
if($this-&gt;emailCheck($strAddress)){
$this-&gt;arrBCC[] = $strAddress;
return 1;
}else{
return 0;
}
}

/*
*
*   @Method:      addReplyTo
*   @Parameters:   1
*   @Param-1:      strEmail - String - Holds the reply-to email address
*   @Description:   Adds a reply-to email address
*
*/
function addReplyTo($strEmail){
if($this-&gt;emailCheck($strEmail)){
$this-&gt;addHeader(&quot;Reply-to: $strEmail&quot;);
}
}

/*
*
*   @Method:      setContent
*   @Parameters:   1
*   @Param-1:      strText - String - Holds the email content
*   @Description:   Adds the content of the email
*
*/
function setContent($strText){
$this-&gt;strContent = $strText;
}

/*
*
*   @Method:      setSubject
*   @Parameters:   1
*   @Param-1:      strText - String - Holds the email subject
*   @Description:   Adds the email subject
*
*/
function setSubject($strText){
$this-&gt;strSubject = $strText;
}

/*
*
*   @Method:      setFrom
*   @Parameters:   1
*   @Param-1:      strText - String - Holds the details of who the email is from
*   @Description:   Adds the sender info to the headers
*
*/
function setFrom($strText){
$this-&gt;addHeader(&quot;From: $strText&quot;);
}

/*
*
*   @Method:      setHTML
*   @Parameters:   0
*   @Description:   Sets the email to allow html
*
*/
function setHTML(){
$this-&gt;strContentType = &quot;text/html&quot;;
}

/*
*
*   @Method:      setPlain
*   @Parameters:   0
*   @Description:   Sets the email to plain text
*
*/
function setPlain(){
$this-&gt;strContentType = &quot;text/plain&quot;;
}

/*
*
*   @Method:      setPriority
*   @Parameters:   1
*   @Param-1:      numPriority - Number - The email priority
*   @Description:   Sets the email priority from 1 - Urgent to 5 - not so
*
*/
function setPriority($numPriority){
$this-&gt;numPriority = $numPriority;
}

/*
*
*   @Method:      addReadConfirmationEmail
*   @Parameters:   1
*   @Param-1:      strEmail - String - Email address to send read confirmation to
*   @Description:   Ensures that a confirmation email is sent when read
*
*/
function addReadConfirmationEmail($strEmail){
if($this-&gt;emailCheck($strEmail)){
$this-&gt;addHeader(&quot;Disposition-Notification-To: &lt;$strEmail&gt;&quot;);
}
}

/*
*
*   @Method:      addHeader
*   @Parameters:   1
*   @Param-1:      strText - String - Holds the header details
*   @Description:   Adds the header details
*
*/
function addHeader($strText){
$this-&gt;arrHeader[] = $strText;
}

/*
*
*   @Method:      addAttachment
*   @Parameters:   3
*   @Param-1:      strFile - String - The file that you want to attach
*   @Param-1:      strName - String - The name of the attachment you want displayed
*   @Param-1:      strType - String - The MIME type of the file
*   @Description:   Adds an attachment to be sent with the email
*
*/
function addAttachment($strFile, $strName, $strType){
//check to make sure the file exists
if(file_exists($strFile)){
$this-&gt;arrAttachments[] = array('path' =&gt; $strFile, 'name' =&gt; $strName, 'type' =&gt; $strType);
}
}

/*
*
*   @Method:      send
*   @Parameters:   0
*   @Description:   Sends the email to all the required people
*
*/
function send(){
//get all the emails in a string to use
$strTo = implode(&quot;, &quot;, $this-&gt;arrTo);

//add any CC addresses if needed
if($this-&gt;arrCC){
$this-&gt;addHeader(&quot;Cc: &quot;.implode(&quot;, &quot;, $this-&gt;arrCC));
}

//add any BCC addresses if needed
if($this-&gt;arrBCC){
$this-&gt;addHeader(&quot;Bcc: &quot;.implode(&quot;, &quot;, $this-&gt;arrBCC));
}

//append any attachments to the end of the content
if(count($this-&gt;arrAttachments)){
$this-&gt;appendAttachments();
}

//add the additional headers
$this-&gt;addAdditionalHeaders();

//implode the headers as they need to be in a single string
$strHeader = implode(&quot;\r\n&quot;, $this-&gt;arrHeader);

//send the email
mail($strTo, $this-&gt;strSubject, $this-&gt;strContent, $strHeader);
}

/*
*
*   @Method:      appendAttachments
*   @Parameters:   0
*   @Description:   Appends any attachments to the end of the email content
*
*/
function appendAttachments(){
//create a unique boundary value
$strBoundary = &quot;H2O-&quot;.time();

//add the boundary to the headers
$this-&gt;addHeader(&quot;Content-Type: multipart/alternitive; boundary=$strBoundary&quot;);

//if there is content to the email already we need to add the boundary and content type
if($this-&gt;strContent){
$strContent = &quot;-$strBoundary\r\n&quot;;
$strContent .= &quot;Content-Transfer-Encoding: {$this-&gt;strEncoding}\r\n&quot;;
$strContent .= &quot;Content-type: {$this-&gt;strContentType}; charset={$this-&gt;strCharSet}\r\n\r\n&quot;;

$this-&gt;strContent = $strContent.$this-&gt;strContent.&quot;\r\n\r\n\r\n&quot;;
}

//loop through all the attachments
foreach($this-&gt;arrAttachments as $arrFile){
//read the content of the file into a string and base64 encode and split into the correct chunk size
$strData = chunk_split(base64_encode(implode(&quot;&quot;, file($arrFile['path']))));

//add the attachments
$strAttachment = &quot;-$strBoundary\r\n&quot;;
$strAttachment .= &quot;Content-Transfer-Encoding: base64\r\n&quot;;
$strAttachment .= &quot;Content-Type: {$arrFile['type']}; name={$arrFile['name']}\r\n&quot;;
$strAttachment .= &quot;Content-Disposition: attachment; filename={$arrFile['name']}\r\n\r\n&quot;;
$strAttachment .= &quot;$strData\r\n&quot;;

//add the attachment to the email content
$this-&gt;strContent .= $strAttachment;

unset($strAttachment);
}

//add the closing boundary
$this-&gt;strContent .= &quot;-$strBoundary-&quot;;
}

/*
*
*   @Method:      addAdditionalHeaders
*   @Parameters:   0
*   @Description:   Adds additional headers for content type and priority etc
*
*/
function addAdditionalHeaders(){
$this-&gt;addHeader(&quot;MIME-Version: 1.0&quot;);

//add the content type and charset if there are no attachments
if(!count($this-&gt;arrAttachments)){
$this-&gt;addHeader(&quot;Content-type: {$this-&gt;strContentType}; charset={$this-&gt;strCharSet}&quot;);
}

//add the priority
$this-&gt;addHeader(&quot;X-Priority: $this-&gt;numPriority&quot;);
}

/*
*
*   @Method:      emailCheck
*   @Parameters:   1
*   @Param-1:      strAddress - String - Holds an email address
*   @Description:   Checks to ensure that the email address is valid
*
*/
function emailCheck($strAddress){
if(ereg(&quot;^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$&quot;, $strAddress)){
return 1;
}else{
return 0;
}
}
}

?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/09/12/grab-link-megaroticcom/" rel="bookmark">Grab link megarotic.com</a></li><li><a href="http://blog.thuongtin.net/2009/04/23/autoit-send-mail/" rel="bookmark">[AutoIt] Send mail</a></li><li><a href="http://blog.thuongtin.net/2008/09/09/gui-email-dang-html-voi-ham-mail/" rel="bookmark">Gửi email dạng HTML với hàm mail()</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/kiem-tra-tinh-hop-le-cua-dia-chi-email/" rel="bookmark">Kiểm tra tính hợp lệ của địa chỉ email</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/tao-1-file-download-file/" rel="bookmark">Tạo 1 file download file</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=15&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/09/10/simple-email-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
