[Solve]PHP Warning: ftp_put(): PORT command successful

October 3rd, 2013

PHP Warning:  ftp_put(): PORT command successful. in /mnt/drive2/cron_job/ftp.php on line 49

I got this problem. And I check the solution on the website – add the ftp_pasv() after ftp_login()

But I still got this problem.  And I found out the problem in PHP. The problem is the command exceed the length. Please check your path.

PHP, Program , ,

PHP Filter User agent in session – Bot

February 2nd, 2012

由於php session 儲存在 database, 所以當有bot出現的時候, 我看到session 會儲存大量bot session, 所以要檢查user agent 是否bot. 那bot 就不會儲存session (database, file).

function isNotBot(){

$bots = array(
‘msn’ => ‘http://search.msn.com/msnbot.htm’,
‘yahoo’ => ‘http://help.yahoo.com/help/us/ysearch/slurp’,
‘WebAlta’ => ‘http://www.webalta.net/ru/about_webmaster.html’,
‘google’ => ‘http://www.google.com/bot.html’,
‘media_google’ => ‘mediapartners-google’,
‘soso’ => ‘http://help.soso.com/webspider.htm’
);

$agent = strtolower($_SERVER[‘HTTP_USER_AGENT’]);
foreach($bots as $name => $bot)
{
if(stripos($agent,$bot)!==false)
{
//echo $name;
return false;
}
}

//if( strpos( $_SERVER[‘HTTP_USER_AGENT’], “Googlebot” ) !== false )
//return false;
return true;
}

if(isNotBot())
session_start();

PHP, Program , , , ,

PHP – sort different

June 13th, 2011

<?php
$a = array(2,    "a",  "11", 2);
$b = array(2,    "11", "a",  2);
sort($a);
var_dump($a);
sort($b);
var_dump($b);


/*

Output:

array(4) {
  [0]=>
  string(2) "11"
  [1]=>
  string(1) "a"
  [2]=>
  int(2)
  [3]=>
  int(2)
}
array(4) {
  [0]=>
  int(2)
  [1]=>
  int(2)
  [2]=>
  string(2) "11"
  [3]=>
  string(1) "a"
}

 

*/

?>

PHP , ,

過濾用戶提交過來的GLOBALS信息

June 6th, 2011

if (isset($_REQUEST[‘GLOBALS’]) OR isset($_FILES[‘GLOBALS’])) {
exit(‘Request tainting attempted.’);
}

眾所周知,當php.ini裡面的register_globals=on時,各種變量都被注入代碼,例如來自HTML 表單的請求變量。再加上PHP 在使用變量之前是無需進行初始化的。那麼就有可能導致不安全,假如有人惡意發出這麼一個get請求”http://yourdomain /unsafe.php?GLOBALS=”,那麼就會清除$GLOBALS變量的值而導致不安全。所以我們可以這樣子寫

PHP, Program , , , ,

PHP – Sudoku Solver

June 5th, 2011

自制program – 數獨破解器

訓練program 結構

PHP, Program , ,

PHP – Random

June 4th, 2011

function random($length = 10)
{
/*
* Random the key a to Z and 0 – 9
*/
$key = array(“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”,
“A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”, “X”, “Y”, “Z”,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
$maxLength = sizeof($key);
$output = “”;
if($length > 0) {
for($i = 0; $i <$length; $i++) {
$output .= $key[rand(0,$maxLength-1)];
}
}

return $output;
}

PHP, Program ,

PHP – Get ip

June 4th, 2011

/*
* Return the real IP address
*/
function getRealIP() {
if ( isset($_SERVER[“REMOTE_ADDR”]) )    {
$myip = $_SERVER[“REMOTE_ADDR”] . ‘ ‘;
} else if ( isset($_SERVER[“HTTP_X_FORWARDED_FOR”]) )    {
$myip = $_SERVER[“HTTP_X_FORWARDED_FOR”] . ‘ ‘;
} else if ( isset($_SERVER[“HTTP_CLIENT_IP”]) )    {
$myip = $_SERVER[“HTTP_CLIENT_IP”] . ‘ ‘;
}
return $myip;
}

PHP, Program ,

PHP Download File in IE

October 29th, 2010

<?php

$filename = ‘file.txt’;
$contents = “”;

header(“Content-type: application/octet-stream”);
header(“Content-Type: application/force-download”);
header(“Content-Description: File Transfer”);
header(“Content-Type: application/download”);
header(‘Content-Disposition: attachment; filename=’.$filename);

$contents .= ‘Test Download File’;

echo $content;

?>

IE 不可以直接打網址(HTTP://WWW.XXX.COM/download.php)去下載file, 只能用link <a href=”./download.php”>Download</a>

PHP , ,

PHP – 查這個function在那裡使用

August 28th, 2010

查這個function a 那裡會被使用

function a(){

echo ‘<pre>’;

print_r(debug_backtrace(true));

echo ‘</pre>’;

}

PHP , ,

How to get the current epoch time in …

June 22nd, 2010

Perl time
PHP time()
Ruby Time.now (or Time.new). To display the epoch: Time.now.to_i
Python import time first, then time.time()
Java long epoch = System.currentTimeMillis()/1000;
Microsoft .NET C# epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
VBScript/ASP DateDiff("s", "01/01/1970 00:00:00", Now())
Erlang calendar:datetime_to_gregorian_seconds(calendar:now_to_universal_time( now()))-719528*24*3600.
MySQL SELECT unix_timestamp(now()) More information
PostgreSQL SELECT extract(epoch FROM now());
Oracle PL/SQL SELECT (SYSDATE - TO_DATE('01-01-1970 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) *
24 * 60 * 60 FROM DUAL
SQL Server SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
JavaScript Math.round(new Date().getTime()/1000.0) getTime() returns time in milliseconds.
Unix/Linux date +%s
Other OS’s Command line: perl -e "print time" (If Perl is installed on your system)

Program , , , , , , , , , , , , , , , ,