PHP Learn

How to find spam sending php script on server

This article can help you to track down outgoing spam using PHP. From php version 5.3.0 we can use the directive mail.log to log who’s calling the function mail(). When someone calls the function mail() from a php script we can get some info about the sender in log. PHP mail.log entries include the full path of the script, line number, To address and headers. 1. Check email log 2. Edit php.ini 3. To enable mail.log, add following line in php.ini under 4. Create lo...

Change Domain and Keep All Links with .htaccess

The following RewriteRule lives in the .htaccess file at olddomain.com and tells any request coming in to that domain to swap olddomain.com out and replace it with newdomain.com. This includes ANYTHING after the trailing slash, like a direct link to a previous post. So http://olddomain.com/this/direct/link gets sent properly to http://newdomain.com/this/direct/link The important part is the [R=301] which sends a 301 (Permanent) Redirect header. That tells search engines that the page ha...

How to XSS attack – JS injection in url

Some websites validate some bits and pieces but fail in other cases assuming that user will not pass anything strange there. French OS Con website is and example of that XSS security risk. If you go to this wage: You will see there is a link go back to previous post. Unfortunately this post's id is take straight from the requested URL (GET parameter) without any cast or validation. It is an common case of XSS errors where page number, date or id is passed around in links and it is n...

HowTo install ImageMagick PHP extension

How to install ImageMagick from YUM repository The easiest way to install ImageMagick extension is to install it from yum repository: 1) Run “yum search imagick” command to check if ImageMagick extension is available in your repositories. If you get the line below – ImageMagick extension is available in your repository and you can install it using “yum install” command 2) Run “yum install php-pecl-imagick” to install ImageMagick extension. 3) Restart Apache webserver. How...

PHP Operator ===

PHP’s === Operator enables you to compare or test variables for both equality and type. Refer below for example.

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...

ThinkPHP中实现gzip压缩

ThinkPHP中似乎没有对gzip的配置选项。不过实现起来还是挺简单的。以下是对 ThinkPHP 2.1 的修改方法。 首先要确定空间是否支持Zlib, 然后找ThinkPHP的控制输出函数output()。 控制输出的文件在 ThinkPHP/Lib/Think/Core 文件夹下,文件名 View.class.php。

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...

PHP Array List of English Stop Words

Stop Words are words which do not contain important significance to be used in Search Queries. Usually these words are filtered out from search queries because they return vast amount of unnecessary information. A better definition is provided below: “Words that do not appear in the index in a particular database because they are either insignificant (i.e., articles, prepositions) or so common that the results would be higher than the system can handle (as in the case of IUCAT where terms suc...

9 Useful PHP Functions and Features You Need to Know

1. Functions with Arbitrary Number of Arguments You may already know that PHP allows you to define functions with optional arguments. But there is also a method for allowing completely arbitrary number of function arguments. First, here is an example with just optional arguments: Now, let’s see how we can build a function that accepts any number of arguments. This time we are going to utilize func_get_args(): 2. Using Glob() to Find Files Many PHP functions have long and des...