Share Coding

Tutorials, Problems, Stuffs …

Category Archives: PHP

How to order / sort number in MYSQL when you have 1, 10, 100?

Sometimes, when you order the record which contain 1, 10, 100

You want:

1F -> 10F -> 100F

Read more of this post

Special Characters between Javascript and PHP

Special Characters: !@#$%^&*()_+{}|:"<>?-=[]\;',./

Javascript: escape();

PHP: unescape();

<?php
function unescape($str) { 
	$ret = ''; 
	$len = strlen($str); 
	for ($i = 0; $i < $len; $i++) { 
		if ($str[$i] == '%' && $str[$i+1] == 'u') { 
			$val = hexdec(substr($str, $i+2, 4)); 
			if ($val < 0x7f) $ret .= chr($val); 
			else if($val < 0x800) $ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f)); 
			else $ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f)); 
			$i += 5; 
		} else if ($str[$i] == '%') { 
			$ret .= urldecode(substr($str, $i, 3)); 
			$i += 2; 
		} 
		else $ret .= $str[$i]; 
	} 
	return $ret; 
}
?>

Create a jQuery + PHP Webpage Template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>Simple jQuery Template</title>

<!-- (jQuery & jQuery UI) SCRIPT and CSS -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<link type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery.ui.all.css" rel="Stylesheet" />

<style>
* {
	box-sizing:border-box;
	-moz-box-sizing:border-box;
	-webkit-box-sizing:border-box;
}
</style>

<script>
$.fn.center = function() {
	this.css('position', 'absolute');
	this.css('left', '50%');
	this.css('top', '50%');
	this.css('margin-left', -this.width() / 2 + 'px');
	this.css('margin-top', -this.height() / 2 + 'px');
	return this;
}
	
$(document).ready(function(){
	
	$("#btnTest").button().center().click(function() {
		alert("Simple jQuery Layout");
	});
	
});
</script>

</head>

<body style="font-family:微軟正黑體, 微软雅黑, Tahoma, Geneva, sans-serif; font-size:12px;overflow-x: hidden">

	<?php echo '<input id="btnTest" type="button" value="Test" />'; ?>

</body>
</html>

phpBB Forum “Template” General Problems

phpBB3.0

1. Why the page do not update while “style/{your style}/template/XXX.html” has been modified?

 
Solution A:
Go to Administration Control Panel -> Styles -> Under Style components -> {Your theme} -> Click refresh

Solution B:
Administration Control Panel -> General -> Load settings -> Recompile stale style components -> Select Yes

Read more of this post

Serve a file without Direct Link on PHP

Some videos wanted to stream to iPhone, but seems IOS do not support RTMP protocol.
But if those videos exposed on direct link, anyone can download it directly (Insecure).
Thus, the following example is a solution that serve a file without direct link to itself.

 
getFile.php

$file = '/usr/local/videos/video.mp4';
$mime_type = "video/mp4";
if ( is_file($file) ) {
	header("Content-type: $mime_type");
	if( isset($_SERVER['HTTP_RANGE']) ) {
		rangeDownload($file);
	} else {
		header("Content-Length: " . filesize($file));
		readfile($file);
	}
} else {
	// some error...
}

 
Read more of this post