Hiển thị các bài đăng có nhãn Php. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Php. Hiển thị tất cả bài đăng

Chủ Nhật, 21 tháng 1, 2018

Chuyển ảnh thành code HTML với PHP

Bài này mình sẽ giới thiệu với mọi người cách chuyển đổi hình ảnh sang code HTML với PHP. Demo sẽ như sau:


1, Thuật toán.
-Thuật toán xử lý hết sức đơn giản với cách thực hiện như sau:

+ Đầu chúng ta sẽ lấy ra hình ảnh cần quét. Và xác định chiều rộng và chiều dài của ảnh.

+ Sau đó chúng ta sẽ thực hiện lặp từng pixel của ảnh từ trái qua phải và từ trên xuống dưới để lấy mã màu (dạng RGB) của từng điểm ảnh.

+ Và khi có được mã màu rồi thì chúng ta sẽ vẽ nó theo code HTML của chúng ta với mỗi điểm ảnh tương ứng với một thẻ span.


-> Đấy đơn giản đúng không giờ mình cùng đi vào thực hành xem thế nào.

2, Thực hành thuật toán.
-Mình sẽ giải thích trong code luôn nhé!

<?php
//Lấy file ảnh từ máy
// Nếu ảnh png thì dùng hàm ImageCreateFrompng
// $img = ImageCreateFrompng('ha-noi.png');

//Nếu ảnh jpg thì dùng hàm ImageCreateFromJpeg
$image = ImageCreateFromJpeg('ha-noi.jpg');

// Lấy ra chiều rộng của ảnh.
$widthImage = imagesx($image);

//Lấy ra chiều cao của ảnh
$heightImage = imagesy($image);

//Lặp chiều cao của ảnh
for ($height = 0; $height < $heightImage; $height++) {

//Lặp chiều rộng của ảnh (Lấy dư ra một để xuống dòng)
for ($width = 0; $width <= $widthImage; $width++) {
//Nếu vị chí hiện tại bằng chiều rộng của ảnh
//thì xuống dòng và tiếp tục.
if ($width == $widthImage) {
echo '<br>';
continue;
}
// Lấy ra màu của điểm ảnh hiện tại
$rgb = ImageColorAt($image, $width, $height);

//Chuyển đổi màu sang dạng RGB.
//chuyển sang red
$red = ($rgb >> 16) & 0xFF;

//Chuyển sang Green
$green = ($rgb >> 8 ) & 0xFF;

//Chuyển sang Blue
$blue = $rgb & 0xFF;

//Hiển thị màu của ảnh dưới dạng html
echo '<span style="font-size:1px;color:rgb(' . $red . ',' . $green . ',' . $blue . ');">#</span>';

}
}

VD: Mình sẽ thử với bức ảnh:


Xem Kết Quả

3, Lời kết.
-Như vậy mình đã giới thiệu với mọi người cách chuyển đổi hình ảnh sang code HTML bằng PHP rồi. Tuy nhiên, cách này chỉ dùng chơi được thôi chứ áp dụng vào thực tế thì hoàn toàn không ổn, vì nó sử dụng quá nhiều tài nguyên (lặp dữ liệu quá nhiều).

Nguồn : Toidicode.com

Thứ Ba, 2 tháng 1, 2018

Upload ảnh sử dụng ajax với PHP

Mấy hôm nay lang thang trên các group thấy mọi người hay vướng về upload ảnh sử dụng ajax với PHP, nên hôm nay mình sẽ demo cho các bạn một ứng dụng upload ảnh sử dụng ajax và PHP đơn giản.


1, Tổng quan.
Nhìn chung nếu muốn hiểu được demo này thì các bạn cần phải có các kiến thức cơ bản sau:
  • PHP : biết được upload file bằng PHP, xử lý chuỗi.
  • Jquery: Biết ajax và thao tác với element cơ bản.


2, Xây dựng.
Cấu Trúc
-Cấu trúc thư mục của ứng dụng sẽ có dạng như sau:
index.html //phần giao diện
upload.php //xử lý upload
uploads // thư mục upload
Giao diện
-Đầu tiên chúng ta sẽ sử dụng HTML và bootstrap để xây dụng giao diện cho ứng dụng.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title> Upload file vs Ajax</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
</head>
<body>
<div class="container">
<div class="panel panel-success">
<div class="panel-body">
<form action="" method="POST" role="form">
<legend>Upload</legend>

<div class="form-group">
<label for="">Chọn file</label>
<input id="file" type="file" name="sortpic" required="" />
</div>
<div class="form-group">
<button id="upload" class="btn btn-primary">Upload</button>
</div>
</form>
<div class="status alert alert-success"></div>
</div>
</div>
</div>
</body>
</html>

Xem Giao Diện

Xử lý ajax
-Tiếp đó chúng ta sẽ sử lý ajax như sau:
<script>
//xử lý khi có sự kiện click
$('#upload').on('click', function() {
//Lấy ra files
var file_data = $('#file').prop('files')[0];
//lấy ra kiểu file
var type = file_data.type;
//Xét kiểu file được upload
var match= ["image/gif","image/png","image/jpg",];
//kiểm tra kiểu file
if(type == match[0] || type == match[1] || type == match[2])
{
//khởi tạo đối tượng form data
var form_data = new FormData();
//thêm files vào trong form data
form_data.append('file', file_data);
//sử dụng ajax post
$.ajax({
url: 'upload.php', // gửi đến file upload.php
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(res){
$('.status').text(res);
$('#file').val('');
}
});
} else{
$('.status').text('Chỉ được upload file ảnh');
$('#file').val('');
}
return false;
});
</script>

Server nhận và xử lý upload
-Ở upload.php chúng ta sẽ xử lý như sau:
<?php
if(isset($_POST) && isset($_FILES['file'])){
$duoi = explode('.', $_FILES['file']['name']); // tách chuỗi khi gặp dấu .
$duoi = $duoi[(count($duoi)-1)];//lấy ra đuôi file
//Kiểm tra xem có phải file ảnh không
if($duoi === 'jpg' || $duoi === 'png' || $duoi === 'gif'){
//tiến hành upload
if(move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $_FILES['file']['name'])){
//Nếu thành công
die('Upload thành công file: '. $_FILES['file']['name']); //in ra thông báo + tên file
} else{ //nếu k thành công
die('Có lỗi!'); //in ra thông báo
}
} else{ //nếu k phải file ảnh
die('Chỉ được upload ảnh'); //in ra thông báo
}
}
else{
die('Lock'); // nếu không phải post method
}

3, Lời Kết.
-Như vậy mình đã xây dựng xong úng dụng upload ảnh bằng ajax + php rồi. Vì đây là basic nên mình chỉ làm đơn giản như vậy thôi, còn trong thực tế có thể nó sẽ phức tạp hơn.


Nguồn: Toidicode.com

Chủ Nhật, 30 tháng 10, 2016

Google New reCaptcha using PHP - Are you a Robot?

Today Google has been introduced new reCaptcha API called Are you a robot? “No Captcha reCaptcha” a complete new design captcha system. This protects your website for spammers and robots, in this post I had implemented new reCaptch API system with HTML login form using PHP. I like the new design it is clean and impressive, hope you will like it. Please take a look quick look at the demo.

Get reCaptcha Key
Click here to create a Google reCaptcha application. Register Your Website Give your website domain details without http:

Google Site Key
You will use this in HTML code.

Google Secret Key This will help your website to communication with Google.

HTML Code
Contains simple HTML code with Google reCaptcha widget snippet. Here you have to modify the Google Site Key value.
<html>
<head>
/* Google reCaptcha JS */
<script src="https://www.google.com/recaptcha/api.js"></script>
</head>
<body>
<form action="" method="post">
Username
<input type="text" name="username" class="input" />
Password
<input type="password" name="password" class="input" />
<div class="g-recaptcha" data-sitekey="Google Site Key"></div>
<input type="submit" value="Log In" />
<span class='msg'><?php echo $msg; ?></span>
</form>
</body>
</html>
index.php Contains PHP code, here you have to modify the Google Secret Key.
<?php
include("db.php");
session_start();

$msg='';
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$recaptcha=$_POST['g-recaptcha-response'];
if(!empty($recaptcha))
{
include("getCurlData.php");
$google_url="https://www.google.com/recaptcha/api/siteverify";
$secret='Google Secret Key';
$ip=$_SERVER['REMOTE_ADDR'];
$url=$google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
$res=getCurlData($url);
$res= json_decode($res, true);
//reCaptcha success check
if($res['success'])
{
//Include login check code
}
else
{
$msg="Please re-enter your reCAPTCHA.";
}

}
else
{
$msg="Please re-enter your reCAPTCHA.";
}

}
?>
Login Check Code This code will verify username and password details in database.
$username=mysqli_real_escape_string($db,$_POST['username']);
$password=md5(mysqli_real_escape_string($db,$_POST['password']));
if(!empty($username) && !empty($password))
{
$result=mysqli_query($db,"SELECT id FROM users WHERE username='$username' and passcode='$password'");
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
if(mysqli_num_rows($result)==1)
{
$_SESSION['login_user']=$username;
header("location: home.php"); //Success redirection page.
}
else
{
$msg="Please give valid Username or Password.";
}

}
else
{
$msg="Please give valid Username or Password.";
}
getCurlData.php CURL function for Google reCaptcha verification. Enable php_curl extension in php.ini configuration file.
<?php
function getCurlData($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
$curlData = curl_exec($curl);
curl_close($curl);
return $curlData;
}
?>
db.php Database configuration file, modify username, password and database values.
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'username');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'database');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>

Thứ Hai, 26 tháng 9, 2016

Import excel vào mysql bằng php


code import Excel data, first you need to have a Excel reader. It should be accurate enough to interpret Excel data as expected. There ‘s a good old Excel reader.
Download PHPExcelReader.
In the downloaded archive, you only need Excel directory with files including oleread.inc and reader.php.
Just extract it where your web server can access.
Next place your excel file or just create one with some dummy data. Make sure this file is readble by the web server.
Finally create your php script to connect with database, read Excel file and insert data into db.

<?php
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read('a.xls');
$conn = mysql_connect("localhost","root","");
mysql_select_db("test",$conn);
for ($x = 2; $x <= count($data->sheets[0]["cells"]); $x++) {
$first = $data->sheets[0]["cells"][$x][1];
$middle = $data->sheets[0]["cells"][$x][2];
$last = $data->sheets[0]["cells"][$x][3];
$sql = "INSERT INTO mytable (First,Middle,Last)
VALUES ('$first','$middle','$last')";
echo $sql."\n";
mysql_query($sql);
}
?>

Thứ Tư, 15 tháng 6, 2016

Share code site Phim online và Joomla Theme miễn phí, download ngay


Codecanyon cùng với Themeforest là công ty con của Envato, rất nổi tiếng trong việc bán theme, scripts và plugins.

Tháng 6 này, script tạo site phim online PHP Watch Movies Script có giá 16$ được đưa vào danh sách June's Free File of the Month cho phép tất cả mọi người có thể tải về miễn phí!

Thao tác rất đơn giản, bạn chỉ cần đăng nhập (đăng ký account mới nếu chưa có) là tải về full source code được ngay.

Xem demo site phim dùng code này tại đây. Nếu cần dùng bạn hãy down ngay về máy nhé, hoặc chia sẻ lại cho những người khác thoải mái.

Ngoài script này ra, tháng 6 bạn còn được tặng một theme Photography Portfolio (giá 48$) dành cho Joomla trên Themeforest khá đẹp mắt, nếu cần bạn hãy tải về tại đây.

DEMO

DOWNLOAD

Chúc bạn một ngày vui vẻ.

Chủ Nhật, 15 tháng 5, 2016

Connect Twitter API with OAuth using PHP.

Few days back I had connected labs.9lessons application to twitter API via OAuth (open protocal secure authorization). In this post I want to explain how to store twitter oauth_token and secret values in to database and how to update status with your own web application.




Database
Here storing twitter authorization token keys. MySQL users table columns uid, uname, passcode, oauth_token, oauth_token_secret
CREATE TABLE users
(
uid INT PRIMARY KEY AUTO_INCREMENT,
uname VARCHAR(50) UNIQUE,
passcode VARCHAR(50),
oauth_token VARCHAR(90),
oauth_token_secret VARCHAR(90)
);

How it works at labs.9lessons
Take a look at this video.



confirm.php
Callback URL - return to after successfully authentication?
include 'db.php';
include 'EpiCurl.php';
include 'EpiOAuth.php';
include 'EpiTwitter.php';
include 'secret.php';
$Twitter = new EpiTwitter($consumerKey, $consumerSecret);
if(isset($_GET['oauth_token']) || (isset($_COOKIE['oauth_token']) && isset($_COOKIE['oauth_token_secret'])))
{
// Twitter user accepted access
if( !isset($_COOKIE['oauth_token']) || !isset($_COOKIE['oauth_token_secret']) )
{
// user comes from twitter
$Twitter->setToken($_GET['oauth_token']);
$token = $Twitter->getAccessToken();
setcookie('oauth_token', $token->oauth_token);
setcookie('oauth_token_secret', $token->oauth_token_secret);
$Twitter->setToken($token->oauth_token, $token->oauth_token_secret);
}
else
{
// user switched pages and came back or got here directly, stilled logged in
$Twitter->
setToken($_COOKIE['oauth_token'],$_COOKIE['oauth_token_secret']);
$user= $Twitter->get_accountVerify_credentials();
$oauth_token=$_COOKIE['oauth_token'];
$oauth_token_secret=$_COOKIE['oauth_token_secret'];

// Storing token keys
$sql=mysql_query("update users SET oauth_token='$oauth_token',
oauth_token_secret='$oauth_token_secret' where username='$user_session'");
header('Location: abc.php'); //Redirecting Page
}
echo "Please re-connect once again click here";
}
This below status(tweet) updated with labs.9lessons.info

update.php
Here $message="Your Status update";
include 'db.php';
include 'EpiCurl.php';
include 'EpiOAuth.php';
include 'EpiTwitter.php';
include 'secret.php';
$tw_sql=mysql_query("select oauth_token,oauth_token_secret from users where user='$user_session'");
$row=mysql_fetch_array($tw_sql);

$oauth_token=$row['oauth_token'];
$oauth_token_secret=$row['oauth_token_secret'];

if(strlen($oauth_token)>0 || strlen($oauth_token_secret)>0 )
{
$Twitter = new EpiTwitter($consumerKey, $consumerSecret);
$Twitter->setToken($oauth_token,$oauth_token_secret);
//$message Status update
$status=$Twitter->post_statusesUpdate(array('status' => $message));
$status->response;
}

If any queries just ask me at facebook.com/srinivas.tamada
db.php
PHP database configuration file

Thứ Bảy, 23 tháng 4, 2016

Twitter OAuth Status Update New Tweet using PHP


Twitter is the most powerful platform that you can express your thoughts with your followers. Few months back Twitter has been updated there OAuth APIs, this tutorial will explain three import systems like, login with Twitter, storing Twitter Oauth tokens into database and update Twitter status message with your own web application. This script helps you to share your web application updates with user Twitter status updates.


Database
Sample database users table columns id, email, oauth_uid, oauth_provider and username

CREATE TABLE `TwitterUpdate` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`uname` varchar(50),
`name` varchar(90),
`oauth_token` varchar(90),
`oauth_token_secret` varchar(90),
PRIMARY KEY (`user_id`),
UNIQUE KEY `uname` (`uname`)
The tutorial contains three folders called facebook,twitter and config with PHP files.
EpiTwitter
-- TwitterConfig.php
-- EpiTwitter.php
-- EpiCurl.php
-- EpiOAuth.php //Twitter Oauth Library
index.php
home.php
db.php
TwitterLogin.php
TwitterCallback.php
TwitterUpdate.php
TwitterLogout.php
Create Twitter Application
You have to create an application and give the details in the following way.

Twitter Application Setup
You have to modify application API key and Api secret.
TwitterConfig.php

<?php
$consumer_key = 'API key';
$consumer_secret = 'API secret';
?>

db.php
Database configuration file, update database details such as username, password and database name.

<?php
session_start();
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'username');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'databaseName');
$connection = @mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE) or die(mysqli_error());
?>

TwitterLogin.php
This code will generate Twitter authorization url.

<?php
include 'EpiTwitter/EpiCurl.php';
include 'EpiTwitter/EpiOAuth.php';
include 'EpiTwitter/EpiTwitter.php';
include 'EpiTwitter/TwitterConfig.php';
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
$TwitterLoginUrl=$twitterObj->getAuthorizationUrl();
header("Location: $TwitterLoginUrl");
?>

index.php
Contains PHP code, hyperlink to TwitterLogin.php file.

<?php
session_start();
//Login session check
if(!empty($_SESSION['TwitterUsername']))
{
header("Location: home.php");
}
?>
//HTML Code
<a href="TwitterLogin.php">Login with Twitter</a>

TwitterCallback.php
Twitter application callback URL, Twitter will send all the OAuth tokens values to following file. Please follow the code comments.

<?php
include 'EpiTwitter/EpiCurl.php';
include 'EpiTwitter/EpiOAuth.php';
include 'EpiTwitter/EpiTwitter.php';
include 'EpiTwitter/TwitterConfig.php';
include("db.php");

$Twitter = new EpiTwitter($consumer_key, $consumer_secret);

if(isset($_GET['oauth_token']) || (isset($_SESSION['oauth_token']) && isset($_SESSION['oauth_token_secret'])))
{

if(empty($_SESSION['oauth_token']) && empty($_SESSION['oauth_token_secret']) )
{
$Twitter->setToken($_GET['oauth_token']);
$token = $Twitter->getAccessToken();
$_SESSION['oauth_token']=$token->oauth_token;
$_SESSION['oauth_token_secret']= $token->oauth_token_secret;
$Twitter->setToken($token->oauth_token, $token->oauth_token_secret);
}
else
{
$Twitter->setToken($_SESSION['oauth_token'],$_SESSION['oauth_token_secret']);
}

$userData= $Twitter->get_accountVerify_credentials();
$TwitterUsername=$userData->screen_name;
$TwitterFullname=$userData->name;
$_SESSION['TwitterUsername']=$TwitterUsername;
$_SESSION['TwitterFullname']=$TwitterFullname;
$oauth_token=$_SESSION['oauth_token'];
$oauth_token_secret=$_SESSION['oauth_token_secret'];
//Checking user availability.
$tw_sql=mysqli_query($connection,"SELECT user_id FROM TwitterUpdate WHERE uname='$TwitterUsername'");

if(mysqli_num_rows($tw_sql) == 0)
{
//Insert values into TwitterUpdate table
$sql=mysqli_query($connection,"INSERT into TwitterUpdate(uname,name,oauth_token,oauth_token_secret) VALUES ('$TwitterUsername','$TwitterFullname','$oauth_token','$oauth_token_secret');");
}
header('Location: home.php'); //Redirecting Page

}
else
{
header('Location: index.php');
}
?>

home.php
This code contains PHP, Javascript(jquery) and simple HTML. Here $("#submit").click(function(){}- submit is the id name of input button. Using $("#message").val("") calling the textarea value.

<?php
session_start();
if(empty($_SESSION['TwitterUsername']))
{
header('Location: index.php');
}
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function()
{
//Displaying character count
$("#message").keyup(function()
{
var A=$.trim($(this).val());
$("#count").html(A.length);
});

//Ajax message update to Twitter.
$("#submit").click(function()
{
var A=$.trim($("#message").val());
var dataString = 'TwitterMessage='+ A ;

if(A.length<=145)
{
$.ajax({
type: "POST",
url: "TwitterUpdate.php", //Ajax Call
data: dataString,
cache: false,
beforeSend: function()
{
$("#submit").val("Updating...");
},
success: function(data)
{
var B=$("#username").val();
var C='https://twitter.com/'+B+'/status/'+data;
$("#link").html('<a href="'+C+'" target="_blank">'+C+'</a>');
$("#submit").val("Post to Twitter");
$("#message").val("").focus();
$("#count").html('0');
}
});
}
else
{
alert("Maximum 145 characters.");
}

return false;
});

});
</script>
//HTML Code
<h1>Welcome to <?php echo $_SESSION['TwitterFullname']; ?></h1>
<form method="post" action="">
<textarea id="message"></textarea><span id="count">0</span>
<input type="hidden" value="<?php echo $_SESSION['TwitterUsername']; ?>" id="username"/>
<input type="submit" id="submit" value="Post to Twitter"/>
<div id="link"></div>
</form>
<a href="TwitterLogout.php">Logout</a>

TwitterUpdate.php
Twitter OAuth status update file.

<?php
include 'EpiTwitter/EpiCurl.php';
include 'EpiTwitter/EpiOAuth.php';
include 'EpiTwitter/EpiTwitter.php';
include 'EpiTwitter/TwitterConfig.php';
include("db.php");
if(isset($_POST['TwitterMessage']) && !empty($_SESSION['TwitterUsername']))
{
$message=mysql_real_escape_string($_POST['TwitterMessage']);
$TwitterUsername=$_SESSION['TwitterUsername'];
//Getting values from TwitterUpdate table.
$tw_sql=mysqli_query($connection,"SELECT oauth_token,oauth_token_secret FROM TwitterUpdate WHERE uname='$TwitterUsername'");
$row=mysqli_fetch_array($tw_sql,MYSQLI_ASSOC);
$oauth_token=$row["oauth_token"];
$oauth_token_secret=$row["oauth_token_secret"];
if(strlen($oauth_token)>0 && strlen($oauth_token_secret)>0 )
{
$Twitter = new EpiTwitter($consumer_key, $consumer_secret);
$Twitter->setToken($oauth_token,$oauth_token_secret);
//Twitter status update
$status=$Twitter->post_statusesUpdate(array('status' => $message));
echo $status->id_str;
}
}
?>

TwitterLogout.php
Session logout this will clear all the session values and it redirect to index.php

<?php
session_start();
unset($_SESSION['TwitterUsername']);
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
session_destroy();
header("location: index.php");
?>

Thứ Hai, 18 tháng 4, 2016

Hướng dẫn tạo radom banner cho blogger


Chào các bạn hôm nay mình xin hướng dẫn các bạn cách tạo radom banner cực đơn giản cho các bạn
Lưu ý : Các bạn phải có hosting để sử dụng nhé vì mình sử dụng code Php :)

Code Php

<?php
$advert = array();
$advert[] = '<a herf="">Link ảnh 1</a>';
$advert[] = '<a herf="">Link ảnh 2</a>';
$advert[] = '<a herf="">Link ảnh 3</a>';
$advert[] = '<a herf="">Link ảnh 4</a>';

shuffle($advert);
echo $advert[0];
?>

Các bạn copy toàn bộ code trên và up lên hosting nhé :D
Code Iframe đặt trên blogger :)

<iframe scrolling="no" width="730" style="overflow:hidden; border:0" src="http://domainxxx/radom-banner.php">

Link http://domain.xxx/radom-banner.php -> các bạn thay thế bằng link của các bạn :)
Ở đây mình đặt ở trên nên tỉ lên là 728x90px các bạn có thể tùy chỉnh nếu muốn

Chúc các bạn thành công

Thứ Bảy, 16 tháng 4, 2016

Share Full Code Php Auto Comment + Like


Hôm nay mình xin share code Auto Like + Comment bằng Code Php nhé :)

Lưu Ý: Các bạn phải có Host ( Host mua thì sẻ hay hơn host free )
Các bạn vào google để xem cách lấy long token hoặc có thể comment để mình hướng dẫn nhé :)

Còn đây là Full Code cho ai cần dùng đến ...

Auto Like And Comment Success Full :v
<?php
error_reporting(0);
##############SETTING BOT####################
$bot['like'] = true; //Bot Like
$bot['ck_k'] = true; // Comment
$bot['ck_u'] = true; // General Comment
$bot['time'] = false; // Date
$bot['aces'] = "Long Token "; // YOUR TOKEN
##############END OF SETTING#############

com_like($cl,$ck,$cu,$tm,$access_token);


com_like($bot['like'],$bot['ck_k'],$bot['ck_u'],$bot['time'],$bot['aces']);

function cmn($text,$ck,$cu){
##########umum
$cmn_umum = array(":3",
":*",
"Hi! <name> <aku> Ban khoe khong?",
"ωσω?? Ļιкє тнιѕ <name>, ",
"Iam coming <name> .. please dont angry again :P.. ",
"<name> Like Back Oke :D ",
"<name> How Are you ? ",
"<3 <name> ",
"I will back <name> on your stat ;) тнχ",
"This is Robot ? <name> ●●●ωωкωкωкωк ?",

);

//comment automatically depending on the situation

$comment = array(
array(
array("Night",
"Sleep",
"where",
),
array("Dont SLeep Please :( ",
"anywhere :) ",
"you want to sleep ? <name> ?",
)
),
array(
array("Hope",
"hopefully",
"amin",
),
array("αмιη <name>●● ",
"why <name>●?",
"Allah Bless you <name>",
)
),
array(
array("morning",
"goodmorning",
"m0rning",
"mornng",
"Good morning",
"m0rn1ng",
"page",
),
array("yes morning bro <name> ",
"good morning to <name>",
"Thank you <name>",
)
),
array(
array("night",
"good night",
"godninght",
"ni9ht",
),
array("Good night <name> ",
"нι <name> Sweet dream ",
"yes night <name> dont forget to pray?",
)
),
array(
array("sweet child of mine",
"my heart is broken",
),
array("who sings ? i think Obama lol :v hahah ",
)
),
array(
array("sick",
"damn",
"hurt",
),
array("dont sad <name> pray will make you happy ",
" hope Allah bless you :) ",
)
),
array(
array("God",
"Allah",
"ya allah",
),
array("Dont Sad Bro <name> Allah bless you anywhere",
)
),
array(
array("cool",
"handsome",
"rock",
"beautiful",
),
array("yes iam very cool <name> ",
"you say <aku> handsome ? Thank you :) ",
)
),
array(
array("promise",
"InsyaAllah",
),
array("dont promise <name> i believe you ",
)
),
array(
array("Hot",
"very hot",
"weather hot",
"h0t",
),
array("swimming bro <name> lol :v ",
)
),
array(
array("fasting",
"imsak",
"sahur",
"iftar",
"waiting afternoon",
),
array("Masya Allah <name>",
"awesome <name> :) ",
"Good Job <name> :D ",
)
),
);
$komentar = '';
$cr_kondisi=false;
foreach($comment as $cx){
foreach($cx[0] as $ct){
if(ereg($ct,$text)){
$cr_kondisi=true;
$komentar = $cx[1][rand(0,count($cx[1]) - 1)];
}
}
}
if($cr_kondisi==true && $ck==true){
return $komentar;
}else{
if($cu==true){ return $cmn_umum[rand(0,count($cmn_umum) - 1)]; }
}
}
#######################################
function com_like($cl,$ck,$cu,$tm,$access_token){
$beranda = json_decode(httphit("https://graph.facebook.com/me/home?fields=id,from,type,message&limit=100&access_token=".$access_token))->data;
$saya_cr = json_decode(httphit("https://graph.facebook.com/me?access_token=".$access_token));
if($beranda){
foreach($beranda as $cr_post){
if(!ereg($saya_cr->id,$cr_post->id)){
$log_cr = simlog($cr_post->id);
if($log_cr==true){
if($ck==true){
$url_ck = cmn($cr_post->message,$ck,$cu);
$url_ck = str_replace("<name>",$cr_post->from->name,$url_ck);
$url_ck = str_replace("<aku>",$saya_cr->first_name,$url_ck);
if($tm==true){ $url_ck = $url_ck.wkthit().kecepatan().konter() ; }
$url_ck = urlencode($url_ck);
if($ck==true OR $cu==true){
httphit("https://graph.facebook.com/".$cr_post->id."/comments?method=POST&message=".$url_ck."&access_token=".$access_token);
}
if($cl==true){
httphit("https://graph.facebook.com/".$cr_post->id."/likes?method=POST&access_token=".$access_token);
}
}
}
}
}
}
}
#######################################
function httphit($url){
return file_get_contents($url);
}

function kecepatan() {
$waktu="
";

$gentime = microtime();
$gentime = explode(' ',$gentime);
$gentime = $gentime[0];
$pg_end = $gentime;
$totaltime = ($pg_end - $pg_start);
$showtime = number_format($totaltime, 1, '.', '');
return "$waktu ★ Comment Late $showtime Second ";
}
function konter() {
$sempak="
";
$filename = 'hitcount.txt';
$handle = fopen($filename, 'r');
$hits = trim(fgets($handle)) + 1;
fclose($handle);

$handle = fopen($filename, 'w');
fwrite($handle, $hits);
fclose($handle);
return "$sempak ★ Sequence $hits Complete :ᴅ ..!!";
}
function wkthit(){
$ent="
";
$hari=gmdate("D", time()+60*60*7);
if((gmdate("D", time()+60*60*7))=="Sun"){ $hari="Sunday"; }
if((gmdate("D", time()+60*60*7))=="Mon"){ $hari="Monday"; }
if((gmdate("D", time()+60*60*7))=="Tue"){ $hari="Tuesday"; }
if((gmdate("D", time()+60*60*7))=="Wed"){ $hari="Wednesday"; }
if((gmdate("D", time()+60*60*7))=="Thu"){ $hari="Thursday"; }
if((gmdate("D", time()+60*60*7))=="Fri"){ $hari="Friday"; }
if((gmdate("D", time()+60*60*7))=="Sat"){ $hari="Saturday"; }
$jam="Time : ".gmdate("g:i a", time()+60*60*7);
return $ent.$ent."★ ".$hari." - Date : ".gmdate("j - m - Y", time()+60*60*7)." - ".$jam." $showtime";
}
function simlog($cr_id) {
$fname = "cr_log.txt";
$lihatiplist=fopen ($fname, "rb");
$text='';
if($lihatiplist){
$spasipol = "";
do {
$barislistip = fread($lihatiplist, 512);
if(strlen($barislistip) == 0){ break; }
$spasipol .= $barislistip;
} while(true);
fclose ($lihatiplist);
for ($i = 1; $i <= 10; $i++) {$spasipol = str_replace(" ","",$spasipol);}
$text=$text.$spasipol;
}else{$text="";}
if(ereg($cr_id,$text)){
return false;
}else{
$text = $text.$cr_id;
$w_file=@fopen($fname,"w") or bberr();
if($w_file) {
@fputs($w_file,$text);
@fclose($w_file);
}
return true;
}
}
?>