how to get php info ?
<pre>
phpinfo();
</pre>
Friday, October 19, 2012
Get datetime with php
how to get datetime with php?
$datetime = date('Y-m-d H:i:s');
echo $datetime;
$datetime = date('Y-m-d H:i:s');
echo $datetime;
Get user IP with PHP
How to get user ip with php?
Example:
$userIp = $_SERVER['REMOTE_ADDR'];
echo $userIp;
Example:
$userIp = $_SERVER['REMOTE_ADDR'];
echo $userIp;
php generate random number
How to generate randum number with php
$rand = rand(1, 1000); //generate rand number from 1 to 1000
echo $rand;
$rand = rand(1, 1000); //generate rand number from 1 to 1000
echo $rand;
php BAN system
php BAN system
How to create easy ip ban system with PHP?
system for ban user ip
CREATE TABLE `bans` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ip` CHAR( 15 ) NOT NULL ,
) ENGINE = MYISAM
example template:
<div>
<form action="" method="post">
Ban IP: <input type="text" name="ip" value="***.***.***.***" /> <br />
<input type="submit" name="ban" value="ban this ip" />
</form>
</div>
php code:
<?php
if(isset($_POST['ban'])){
mysql_query("
INSERT INTO
users (ip)
VALUES
('" . $_POST['ip'] . "')
");
}
?>
function checkUserBan(){
$checkUserBan_sql = "
SELECT
*
FROM
bans
";
$checkUserBan_res = mysql_query($checkUserBan_sql);
$banIp = array();
while($checkBans = mysql_fetch_array($checkUserBan_res)){
$banIp[] = $checkBans['ip'];
}
if(in_array($_SERVER['REMOTE_ADDR'], $banIp)){
Header('Location: /bans.php');
exit;
}
}
paste function "checkUserBan();" at the top of every file on your site without bans.php
How to create easy ip ban system with PHP?
system for ban user ip
CREATE TABLE `bans` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ip` CHAR( 15 ) NOT NULL ,
) ENGINE = MYISAM
example template:
<div>
<form action="" method="post">
Ban IP: <input type="text" name="ip" value="***.***.***.***" /> <br />
<input type="submit" name="ban" value="ban this ip" />
</form>
</div>
php code:
<?php
if(isset($_POST['ban'])){
mysql_query("
INSERT INTO
users (ip)
VALUES
('" . $_POST['ip'] . "')
");
}
?>
function checkUserBan(){
$checkUserBan_sql = "
SELECT
*
FROM
bans
";
$checkUserBan_res = mysql_query($checkUserBan_sql);
$banIp = array();
while($checkBans = mysql_fetch_array($checkUserBan_res)){
$banIp[] = $checkBans['ip'];
}
if(in_array($_SERVER['REMOTE_ADDR'], $banIp)){
Header('Location: /bans.php');
exit;
}
}
paste function "checkUserBan();" at the top of every file on your site without bans.php
PHP Get image size and type - width, height, type.
Get image size and type - width, height, type.
<?php
list($width, $height, $type) = getimagesize('/path/to/your/image/image.jpg');
echo $widht . ' - ' . $height . ' - ' . $type;
?>
<?php
list($width, $height, $type) = getimagesize('/path/to/your/image/image.jpg');
echo $widht . ' - ' . $height . ' - ' . $type;
?>
jQuery add or remove html class
<style>
.hidden{
display: none;
}
</style>
<div id="example">
example text
</div>
<input type="button" name="button" value="add class hidden" id="addClass" />
<script type="text/javascript">
$('#addClass').click(function() {
$('#example').addClass('hidden');
});
</script>
OR remove
<style>
.hidden{
display: none;
}
</style>
<div id="example" class="hidden">
example text
</div>
<input type="button" name="button" value="add class hidden" id="addClass" /><script type="text/javascript">
$('#addClass').click(function() {
$('#example').removeClass('hidden');
});
</script>
.hidden{
display: none;
}
</style>
<div id="example">
example text
</div>
<input type="button" name="button" value="add class hidden" id="addClass" />
<script type="text/javascript">
$('#addClass').click(function() {
$('#example').addClass('hidden');
});
</script>
OR remove
<style>
.hidden{
display: none;
}
</style>
<div id="example" class="hidden">
example text
</div>
<input type="button" name="button" value="add class hidden" id="addClass" /><script type="text/javascript">
$('#addClass').click(function() {
$('#example').removeClass('hidden');
});
</script>
jQuery get input value
get input value with jQeury
<input type="text" name="name" value="Test" id="inputID" />
<input type="button" name="button" value="get Input value" id="getVal" />
<script type="text/javascript">
$('#getVal').click(function() {
var inputVal = $('#inputID').val();
aler(inputVal);
});
</script>
<input type="text" name="name" value="Test" id="inputID" />
<input type="button" name="button" value="get Input value" id="getVal" />
<script type="text/javascript">
$('#getVal').click(function() {
var inputVal = $('#inputID').val();
aler(inputVal);
});
</script>
Php function check username
Php function check username
function checkUsername($username){
if(preg_match("/^[a-zA-Z0-9-_]+$/", $username)) {
if(strlen($username) >= 3){
if(empty($result)){
$result = 'success';
}
}else{
$result = 'invalid';
}
}else{
$result = 'invalid';
}
return $result;
}
<?php
if(checkUsername('YourUsername') == 'success'){
echo 'Username is correct!';
}else{
echo 'Invalid Username';
}
?>
function checkUsername($username){
if(preg_match("/^[a-zA-Z0-9-_]+$/", $username)) {
if(strlen($username) >= 3){
if(empty($result)){
$result = 'success';
}
}else{
$result = 'invalid';
}
}else{
$result = 'invalid';
}
return $result;
}
<?php
if(checkUsername('YourUsername') == 'success'){
echo 'Username is correct!';
}else{
echo 'Invalid Username';
}
?>
php register system
How to make user register system with username checker?
1. Create table with 5 rows.
example: table name = users
CREATE TABLE `users` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`password` CHAR( 32 ) NOT NULL ,
`username` VARCHAR( 50 ) NOT NULL ,
`email` VARCHAR( 50 ) NOT NULL ,
`real_name` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM
example register.php file:
<?php
if(isset($_POST['register'])){
$checkUsername_sql = "
SELECT
username
FROM
users
WHERE
username = '" . $_POST['username'] . "'
";
$checkUsername_res = mysql_query($checkUsername_sql);
$checkUsername = mysql_fetch_array($checkUsername_res);
$getUsername = $checkUsername['username'];
if(!$getUsername){
mysql_query("
INSERT INTO
users (username, password, email, real_name)
VALUES
('" . $_POST['username'] . "', '" . md5($_POST['password']) . "', '" . $_POST['email'] . "', '" . $_POST['real_name'] . "')
");
$result = 'Success';
}else{
$result = 'This username exist!';
}
}
?>
example register template file:
<html lang="en">
<head>
<title>Sample HTML File</title>
</head>
<body bgcolor="white">
<?
if(isset($_POST['register']) AND isset($result)){?>
echo $result;
}
?>
<div>
<form action="" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
E-mail: <input type="text" name="email" /> <br />
Real Name: <input type="text" name="real_name" /> <br />
<input type="submit" name="register" value="Register" />
</form>
</div>
</body>
</html>
1. Create table with 5 rows.
example: table name = users
CREATE TABLE `users` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`password` CHAR( 32 ) NOT NULL ,
`username` VARCHAR( 50 ) NOT NULL ,
`email` VARCHAR( 50 ) NOT NULL ,
`real_name` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM
example register.php file:
<?php
if(isset($_POST['register'])){
$checkUsername_sql = "
SELECT
username
FROM
users
WHERE
username = '" . $_POST['username'] . "'
";
$checkUsername_res = mysql_query($checkUsername_sql);
$checkUsername = mysql_fetch_array($checkUsername_res);
$getUsername = $checkUsername['username'];
if(!$getUsername){
mysql_query("
INSERT INTO
users (username, password, email, real_name)
VALUES
('" . $_POST['username'] . "', '" . md5($_POST['password']) . "', '" . $_POST['email'] . "', '" . $_POST['real_name'] . "')
");
$result = 'Success';
}else{
$result = 'This username exist!';
}
}
?>
example register template file:
<html lang="en">
<head>
<title>Sample HTML File</title>
</head>
<body bgcolor="white">
<?
if(isset($_POST['register']) AND isset($result)){?>
echo $result;
}
?>
<div>
<form action="" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
E-mail: <input type="text" name="email" /> <br />
Real Name: <input type="text" name="real_name" /> <br />
<input type="submit" name="register" value="Register" />
</form>
</div>
</body>
</html>
Read file with php
How to read file with php?
example:
Text file name - example.txt
php code:
<?php
$file = '/path/to/file/example.txt';
foreach($file AS $row){
echo $row . "\n";
}
?>
example:
Text file name - example.txt
php code:
<?php
$file = '/path/to/file/example.txt';
foreach($file AS $row){
echo $row . "\n";
}
?>
Thursday, October 11, 2012
Convert text with iconv
Convert from UTF-8 to windows-1251
example:
example:
$text = 'Hello world';
iconv('utf8', 'windows-1251', $text);
cutting text with php
function abbreviate($text, $val){
$text = iconv('utf8', 'windows-1251', $text);
if(strlen($text) > $val){
$text = substr($text, 0, $val) . '...';
$text = iconv('windows-1251', 'utf8', $text);
}else{
$text = iconv('windows-1251', 'utf8', $text);
}
return $text;
}
$text = iconv('utf8', 'windows-1251', $text);
if(strlen($text) > $val){
$text = substr($text, 0, $val) . '...';
$text = iconv('windows-1251', 'utf8', $text);
}else{
$text = iconv('windows-1251', 'utf8', $text);
}
return $text;
}
How to List A Directory Contents Using PHP (Recursive)
function listDirectory($path) { $handle = @opendir($path); while (false !== ($file = readdir($handle))) { if ($file == '.' || $file == '..') continue; if ( is_dir("$path/$file")) { echo "$path/$file\n"; listDirectory("$path/$file"); } else { echo "$path/$file\n"; } } closedir($handle); } listDirectory("tutorials");
Starting the Linux from network
debootstrap –arch i386 wheezy /mnt/hdd5/32/wheezy http://ftp.bg.debian.org/debian
debootstrap –arch i386 oneiric /mnt/hdd5/32/oneiric http://archive.ubuntu.com/ubuntu/
chroot /wheezy
apt-get install linux-image-3.0.0-1-486
edit: initramfs.conf
BOOT=nfs
mkinitramfs -o initrd.img.netboot 3.0.0-1-486
edit: /etc/network/interfaces
In case you do need or want to set up a swapfile, here’s what I did to get one working:
debootstrap –arch i386 oneiric /mnt/hdd5/32/oneiric http://archive.ubuntu.com/ubuntu/
chroot /wheezy
apt-get install linux-image-3.0.0-1-486
edit: initramfs.conf
BOOT=nfs
mkinitramfs -o initrd.img.netboot 3.0.0-1-486
edit: /etc/network/interfaces
# This file describes the network interfaces available on your systemAdding a swap file
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#allow-hotplug eth0
#iface eth0 inet dhcp
iface eth0 inet manual
In case you do need or want to set up a swapfile, here’s what I did to get one working:
sudo apt-get install dphys-swapfilethis package sets up a swap file at /var/swap that is 2x your current ram. however, it still doesn’t setup the swapfile on its own, though it does try. to get the swap file working the rest of the way, do:
sudo losetup /dev/loop0 /var/swapthen, run top and you will see you have a swap file. however, put in as much ram as you need for what you are going to run, and just look at your swap file as “in case of emergency”, because it is not efficient as a ram or a regular swap file, but should keep something from crashing. I’m running mythtv on top of a full feisty desktop, and tried it with 256mb ram, and myth-frontend would crash when i would try to bring it up. with the swap file, it would launch, but would take a while. i added an additional 256mb to bring the total to 512mb and it runs flawless, and i add the swap file just in case. i just make a script for it to set up the swap file at boot.
sudo swapon /dev/loop0
USB Audio on boot
/etc/modprobe.d/alsa-base.conf
add:
# Assign USB Audio as default sound card
options snd_usb_audio index=-1
disable:
# Keep snd-usb-audio from beeing loaded as first soundcard
#options snd-usb-audio index=-2
add:
# Assign USB Audio as default sound card
options snd_usb_audio index=-1
disable:
# Keep snd-usb-audio from beeing loaded as first soundcard
#options snd-usb-audio index=-2
Justin Bieber Robbed in Washington, Singer Tweets
Justin Bieber says some of his belongings were stolen during a show in Washington state.
The
pop star tweeted to his nearly 29 million followers that he and his
tour manager were victimized during the show Tuesday night at the
Tacoma Dome. He didn't lay out exactly what was stolen, but
referenced a computer and a camera. He said what bothers him the
most is that he had a lot of "personal footage" on them.
He adds that "people should respect other's property."
A Tacoma police spokesman says officers are not investigating because no police report has been filed.
Gagnam style Lyrics
Oppan Gangnam Style
Gangnam Style
Najeneun ddasarowun inganjeogin yeoja
Keopi hanjaneui yeoyureul aneun pumgyeok ittneun yeoja
Bami omyeon shimjangi ddeugeowojineun yeoja geureon banjeon ittneun yeoja
Naneun sanai
Najeneun neomankeum ddasarowun geureon sanai
Keopi shikgido jeone One Shot ddaerineun sanai
Bami omyeon shimjangi teojyeobeorineun sanai
Geureon sanai
Aremdawo sarangseurowo
Geurae neo (Hey!)
Geurae baro neo (Hey!)
Areumdawo sarangseurowo
Geurae neo (Hey!)
Geurae baro neo (Hey!)
Jigeumbuteo gal ddaekkaji gabolkka
Oppan Gangnam Style
Gangnam Style
Op-Op-Op-Op
Oppan Gangnam Style
Gangnam Style
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Eh, Eh, Eh, Eh, Eh, Eh
Jeongsokhae boijiman nol ddaen noneun yeoja
Iddaeda shipeumyeon mukkeottdeon meori puneun yeoja
Garyeottjiman wenmanhan nochulboda yahan yeoja geureon gangjakjeogin yeoja
Naneun sanai
Jeonjanha boijiman nol ddaen noneun sanai
Ddaega dweimyeon wanjeon michyeobeorineun sanai
Geunyukboda sasangi ultungbultung han sanai
Geureon sanai
Aremdawo sarangseurowo
Geurae neo (Hey!)
Geurae baro neo (Hey!)
Areumdawo sarangseurowo
Geurae neo (Hey!)
Geurae baro neo (Hey!)
Jigeumbuteo gal ddaekkaji gabolkka
Oppan Gangnam Style
Gangnam Style
Op-Op-Op-Op
Oppan Gangnam Style
Gangnam Style
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Eh, Eh, Eh, Eh, Eh, Eh
Ttwineun nom
Geu wie naneun nom
Baby, Baby naneun mwol jom aneun nom
Ttwineun nom
Geu wie naneun nom
Baby, Baby naneun mwol jom aneun nom You know what I’m saying
Oppan Gangnam Style
Eh, Eh, Eh, Eh, Eh, Eh
Eh~Sexy Lady
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Eh, Eh, Eh, Eh, Eh, Eh
Oppan Gangnam Style
Gangnam Style
Najeneun ddasarowun inganjeogin yeoja
Keopi hanjaneui yeoyureul aneun pumgyeok ittneun yeoja
Bami omyeon shimjangi ddeugeowojineun yeoja geureon banjeon ittneun yeoja
Naneun sanai
Najeneun neomankeum ddasarowun geureon sanai
Keopi shikgido jeone One Shot ddaerineun sanai
Bami omyeon shimjangi teojyeobeorineun sanai
Geureon sanai
Aremdawo sarangseurowo
Geurae neo (Hey!)
Geurae baro neo (Hey!)
Areumdawo sarangseurowo
Geurae neo (Hey!)
Geurae baro neo (Hey!)
Jigeumbuteo gal ddaekkaji gabolkka
Oppan Gangnam Style
Gangnam Style
Op-Op-Op-Op
Oppan Gangnam Style
Gangnam Style
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Eh, Eh, Eh, Eh, Eh, Eh
Jeongsokhae boijiman nol ddaen noneun yeoja
Iddaeda shipeumyeon mukkeottdeon meori puneun yeoja
Garyeottjiman wenmanhan nochulboda yahan yeoja geureon gangjakjeogin yeoja
Naneun sanai
Jeonjanha boijiman nol ddaen noneun sanai
Ddaega dweimyeon wanjeon michyeobeorineun sanai
Geunyukboda sasangi ultungbultung han sanai
Geureon sanai
Aremdawo sarangseurowo
Geurae neo (Hey!)
Geurae baro neo (Hey!)
Areumdawo sarangseurowo
Geurae neo (Hey!)
Geurae baro neo (Hey!)
Jigeumbuteo gal ddaekkaji gabolkka
Oppan Gangnam Style
Gangnam Style
Op-Op-Op-Op
Oppan Gangnam Style
Gangnam Style
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Eh, Eh, Eh, Eh, Eh, Eh
Ttwineun nom
Geu wie naneun nom
Baby, Baby naneun mwol jom aneun nom
Ttwineun nom
Geu wie naneun nom
Baby, Baby naneun mwol jom aneun nom You know what I’m saying
Oppan Gangnam Style
Eh, Eh, Eh, Eh, Eh, Eh
Eh~Sexy Lady
Op-Op-Op-Op
Oppan Gangnam Style
Eh~Sexy Lady
Op-Op-Op-Op
Eh, Eh, Eh, Eh, Eh, Eh
Oppan Gangnam Style
Subscribe to:
Posts (Atom)