PHP's tag archives

PHP Operator ===

PHP’s === Operator enables you to compare or test variables for both equality and type. Refer below for example. [code] <?php //define variables.. $str = '9'; $int = 9; //Returns true since both variable contains the same value.. $res = ($str==$int); //Returns false since the two variables are not of the same type.. $res = ($str===$int); ?> [/code]

Create a REST API with PHP

One of the latest (sort of) crazes sweeping the net is APIs, more specifically those that leverage REST. It’s really no surprise either, as consuming REST APIs is so incredibly easy… in any language. It’s also incredibly easy to create them as you essentially use nothing more than an HTTP spec that has existed for ages. One of the few things that I give Rails credit for is its well thought-out REST support, both for providing and consuming these APIs (as its been explained by all the R...

Create web server on Mac

Apache Start Apache [code] sudo apachectl start [/code] Check it's working: http://localhost/ PHP In /etc/apache2/httpd.conf, uncomment this line: [code] LoadModule php5_module libexec/apache2/libphp5.so [/code] Restart Apache [code] sudo apachectl restart [/code] Fix a warning appearing in phpinfo() Create /etc/php.ini and make it writable [code] cd /etc sudo cp php.ini.default php.ini sudo chmod 666 php.ini [/code] In php.ini, find this line: [co...

ExtJS4 : read posting JSON data in PHP

I am working on a Ext-JS web application which needs to send data to the PHP server side to store. It took me a while to find out how to decodes the receiving JSON string in PHP. Ext-JS Assume you have a model and calling save to send a ajax request. [code] Ext.define('User', { extend: 'Ext.data.Model', fields: ['id', 'name', 'email'], proxy: { type: 'ajax', url : '/users' } }); var user = Ext.create('User', {name: 'Ed Spencer', email: 'ed@...

PHP断点续传 HTTP学习笔记

HTTP断点续传原理是这样的: 1. 客户端需要告诉服务器端从哪里开始。 2.服务端收到请求,返回206状态。并标识续传的起始点及结束点 如下实例 1. 客户端传递请求信息给web服务器,要求从200070字节开始。。 GET /down.zip HTTP/1.1 User-Agent:NetFox RANGE: bytes = 200070- Accept:text/html,image/gif,image/jpeg,*;q=.2,*/*;q=.2 2.服务端收到这个请求以后,返回信息 206 Content-Length = 100222222 Content-Range = bytes 200070 - 100222221/100222222 Content-Type=application/octet-stream 注意:服务端状态 206; Content-Range = bytes (客户端请求续传起始点) - (下载文件大小-1)/(下载文件大小) 在PHP中,是利用$_SERVER['HTTP-RANGE...

Using CURL follow redirects to get final url

This example code shows you how to use curl to follow redirects and get final url. [code] <?php function get_final_url( $url, $timeout = 5 ) { $url = str_replace( "&amp;", "&", urldecode(trim($url)) ); $cookie = tempnam ("/tmp", "CURLCOOKIE"); $ch = curl_init(); curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" ); curl_setopt( $ch, ...

10+ useful codes for develop iPhone friendly websites

Detect iPhones and iPods using Javascript When developing for the iPhone and the iPod Touch, the first thing we have to do is obviously detect it, so we can apply specific code or styles to it. The following code snippets will detect iPhones and iPods using Javascript, and redirect those users to an iPhone specific page. [code] if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { if (document.cookie.indexOf("iphone_redirect=false") == -1)...

50 Powerful Time-Savers For Web Designers

Being a web designer is not easy. Not only do we need to have a good understanding about visual design, typography, information architecture, psychology and a plethora of other disciplines; in our work, we need to take care of so many details, so that our job becomes more and more time-consuming, requiring dozens of tools, attention span and an effective workflow for beautiful, timely and functional results. And this is where small time-savers become handy. Be it a handy checklist, batch inst...

如何用php编写注册后Email激活的验证代码

通过使用Email验证激活的方法,可以有效的帮你阻止恶意的Spam和注册机器人的访问。 用php编写注册后Email验证激活的步骤非常简单,相信几分钟之内你就能学会。 总共需两个页面,register.php 和 verify.php 1. 用户注册表格 register.php [code] <html> <body> <form action="register.php" method="post" name="register"> 用户名:<input type="text" name="username" /> 密码:<input type="password" name="password" /> 电子邮件:<input type="text" name="email" /&...

Tracking the user’s browsing history with PHP and cookie

Here is a sample code to show how using php and cookie to tracking the user's browsing history. The code is used on a shopping website. Hope it helpful to you. [code] /* browsing history */ if (!empty($_COOKIE['ECS']['history'])) { $history = explode(’,', $_COOKIE['ECS']['history']); array_unshift($history, $goods_id); $history = array_unique($history); while (count($history) > $_CFG['history_number']) { array_pop($history); } setcookie(’ECS[hi...