// basic auth
if (
!isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) ||
($_SERVER['PHP_AUTH_USER'] !== 'admin' && $_SERVER['PHP_AUTH_PW'] !== 'test')) {
header('WWW-Authenticate: Basic realm="Enter username and password for admin page."');
header('Content-Type: text/plain; charset=utf-8');
die('このページを見るにはログインが必要です。');
header('Content-Type: text/html; charset=utf-8');
}
Showing posts with label php. Show all posts
Showing posts with label php. Show all posts
Thursday, August 2, 2018
Monday, July 25, 2016
How to check Cron jobs

In the previous article I have shown you to configure cron jobs. Somebody asked me how to check weather cron jons is processing.
So, if you haven't known what is cron jobs please read follow this cron jobs
There are many way to check your cron jobs. To do it you have to :
1- Turn on your terminal and type
-> service crond status (it will show your cron is running or not)
2- you can test it directly with your Shell
-> cd /var/www/vhost/yourroot/html/app -> Console/cake News (if your code error it will be written into log file)
I hope this two steps will be able to involve your part. so if you think this article is important please help to share to everyone.
Set up cron jobs or crontab in Cakephp

Before stating to set up Cron jobs in your server you have understand and know what the Cron jobs is?
Cron is a Linux utility which schedules a command or script on your server to run automatically at a specified time and date. A cron job is the scheduled task itself. Cron jobs can be very useful to automate repetitive tasks.
Cron syntax
*/5 * * * * cd /full/path/to/app && Console/cake myshell myparam # * * * * * command to execute # │ │ │ │ │ # │ │ │ │ │ # │ │ │ │ \───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, # | | | | or use names) # │ │ │ \────────── month (1 - 12) # │ │ \─────────────── day of month (1 - 31) # │ \──────────────────── hour (0 - 23) # \───────────────────────── min (0 - 59)To understand more please follow this link console-and-shells
1 - Create model News.php
App::uses('AppModel', 'Model');
class News extends AppModel
{
public function sendNews()
{
$this->updateAll(array('is_disabled' => 1), array('delivery_time' => date('H:i').':00'));
}
}
2- Create NewsSell in Cosole.
class NewsSell extends AppShell
{
public function main()
{
App::import('Model', 'News');
$News = new News();
$News->sendNews();
}
}
3- Write command in crontab
-> type "crontab -e" in your terminal -> set cron path "*/1 * * * * /var/www/vhosts/yourwebroot/html/app/Console/cake News" -> save
Finally, I hope that this article will help you to get reach at the point.
Problem with cron jobs cakephp.
Sunday, March 27, 2016
Websocket with PHP
There are many ways to create real time web application with PHP, but in this
case I will show you a best websocket library will be useful for making a real
time web application.
What is Websockt?
It is full-duplex (data can transmitted in both directions) clinet/Server commnuication over TCP.
so you will find out that websocket is the new feature of HTML5 that allow Client script to open
the bi-directional socket connections to a server. Now it work on Chrome, Firefox, Safari, Opera
and other browser even on mobile.
What is PHPWebsockets?
It is websocket libray server which written in PHP. You can
download from there : https://github.com/ghedipunk/PHP-WebSockets
testwebsock.php
#!/usr/bin/env php
send($user,$message);
}
protected function connected ($user) {
// Do nothing: This is just an echo server, there's no need to track the user.
// However, if we did care about the users, we would probably have a cookie to
// parse at this step, would be looking them up in permanent storage, etc.
}
protected function closed ($user) {
// Do nothing: This is where cleanup would go, in case the user had any sort of
// open files or other objects associated with them. This runs after the socket
// has been closed, so there is no need to clean up the socket itself here.
}
}
$echo = new echoServer("0.0.0.0","9000");
try {
$echo->run();
}
catch (Exception $e) {
$echo->stdout($e->getMessage());
}
client.html
Please run the client.html and don't forget to lunch the testwebsocket.php via common line.
Wednesday, March 23, 2016
Create nested menu with PHP, Mysql, CSS
How to create a nested menu ,
Before starting to implement , I would sure that you will understand the PHP, Mysql, HTML and CSS.
1- You have to download this project and try to create the database which you will be able to find in the zip file.
2- Test it on your computer, then if everything is fine please look through with the explanation.
- connection.php is the file to connect to database
- example.php is the file to display the menu
- style.css the decoration of menu.
*connection.php
*example.php
*menu.css
Next trip that related to this post will be published soon.
cheer!
Before starting to implement , I would sure that you will understand the PHP, Mysql, HTML and CSS.
1- You have to download this project and try to create the database which you will be able to find in the zip file.
2- Test it on your computer, then if everything is fine please look through with the explanation.
- connection.php is the file to connect to database
- example.php is the file to display the menu
- style.css the decoration of menu.
*connection.php
define('DSN','mysql:host=localhost;dbname=db_menu');
define('USERNAME' , 'root');
define('PASSWORD' , '');
try {
$DB = new PDO(DSN, USERNAME, PASSWORD);
}
catch(PDOException $e) {
echo $e->getMessage();
}
try {
$sql = "SELECT * FROM drop_down";
$result = $DB->query($sql);
$row_count = $result->rowCount();
if($row_count){
$rows = $result->fetchAll(PDO::FETCH_ASSOC);
}
}catch(PDOException $e) {
echo $e->getMessage();
}
*example.php
*menu.css
body {
font: 15px arial, helvetica, sans-serif;
}
ul.multidrop a {
color: #fff;
text-decoration: none;
}
ul.multidrop {
padding: 0;
margin: 0;
background: #DF5B50;
float: left;
}
ul.multidrop ul {
padding: 0;
margin: 0;
background: #DF5B50;
float: left;
}
ul.multidrop li {
padding: 5px;
float: left;
display: inline;
position: relative;
width: 150px;
list-style: none;
cursor: pointer;
}
ul.multidrop li:hover {
background: #3EC4F6;
}
ul.multidrop ul {
position: absolute;
left: 0;
top: 100%;
background: #3EC4F6;
display: none;
}
ul.multidrop ul ul {
left: 100%;
top: 0;
background: #DF5B50;
}
ul.multidrop li:hover > ul {
display: block;
background: #3EC4F6;
}
ul.multidrop li ul li:hover {
background: #DF5B50;
}
Next trip that related to this post will be published soon.
cheer!
Some Useful PHP Tricks You May Not Know
After I read many articles, I found some cool tricks in PHP that are very useful for our projects. Please have a look at 5 tricks below you may satisfy with them.


1. Array in Form Fields
Not only the form input fields that create array like
<input name="name['fullname']">but you can create arrays with checkboxes also.
<label><input type="checkbox" name="hobbies[]" value="Sports" /> Sports</label><br /> <label><input type="checkbox" name="hobbies[]" value="Hiking" /> Hiking</label><br /> <label><input type="checkbox" name="hobbies[]" value="Swimming" /> Swimming</label><br /> <label><input type="checkbox" name="hobbies[]" value="Swimming" /> Watching Movies</label><br />
2. Count Character in a String
When you want to count the string you will think about strlen() function. However, we have a fastest way to count it. Take a look at the following code:
$string = 'testing'; if(isset($string[6])) echo "The string '$string' is at least 7 characters long."; else echo "The string '$string' is less than 7 characters long.";
You treated $string like an array.
3. Use PHP Echo like a Boss
Most of the time we always thought that if we want to concatenate strings with echo, we need to use period. But we can use echo like a function that can replace period with commas instead. Please look at the fastest way to do so:
$string1 = 'test-string1'; $string2 = 'test-string2'; $string3 = 'test-string3'; echo 'String #1: ', $string1, '
'; echo 'String #2: ', $string2, '
'; echo 'String #3: ', $string3, '
';
You will find some more useful trick anywhere else, but these cool tricks is for you. Good luck!
Tuesday, March 22, 2016
Create component to validate IPN (Instant Payment Notification) with Cakephp
It's seem to be for senior programmer, but I just want to let somebody know the benefit or how to implement the IPN of PayPal using PHP or Cakephp, before you can understand what to do with IPN you have take a look this website.
If you don't know at all about Paypal please read the previous article : Paypal
class IpnComponent extends Component
{
public function validate_ipn_data($data_ipn)
{
//Change these with your information
//Sandbox for testing or empty ''
$site = @$_SERVER['SERVER_NAME'];
$paypalmode = $site === 'your_site' ? '' : 'sandbox';
if ($data_ipn) {
if ($paypalmode=='sandbox') {
$paypalmode = '.sandbox';
}
$req = 'cmd=' . urlencode('_notify-validate');
foreach ($data_ipn as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$ch = curl_init();
$url_ = 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr';
$host_ = 'Host: www'.$paypalmode.'.sandbox.paypal.com';
curl_setopt($ch, CURLOPT_URL, $url_);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($host_));
$res = curl_exec($ch);
curl_close($ch);
if (strcmp ($res, "VERIFIED") == 0) {
$item_number = $data_ipn['item_number'];
$model = ClassRegistry::init('Reservation');
$model->id = $item_number;
$model->save(array('is_paid' => 1));
}
}
}
}
1- Please create file in Component and pass the code above, then save.2- You have to load the component in your controller
3- Create a function and call the validate_ipn_data from IPN component
Note : Make sure that your URL pointed to Paypal.
Best PHP Frameworks for Beginner
Now a day, there are many PHP framework such as: CodeIgniter, Yii, Laravel, PHPCake, Zend etc. If you are a beginner PHP Developer who want to develop website with PHP Frameworks, we recommend you to try CodeIgniter.

CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.

It's really easy, best for small projects, very well documented and you find all the answers to your questions on the internet.
Once you're familiar with it, you can start with another framework like CakePHP, Yii and Zend.
Get Started Now

CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.

Why CodeIgniter?
- Framework with a small footprint
- Clear documentation
- Compatibility with standard hosting
- No restrictive coding rules
It's really easy, best for small projects, very well documented and you find all the answers to your questions on the internet.
Once you're familiar with it, you can start with another framework like CakePHP, Yii and Zend.
Get Started Now
phpDesigner 8 Best IDE for Your Next PHP Projects
phpDesigner 8 is a fast PHP IDE and PHP editor with built-in HTML5-, CSS3- and JavaScript editors boosted with features to help you create amazing websites. phpdesigner


The main pro of this one is that it's NOT Java based. This keeps the whole thing quick.
Features:
- Intelligent Syntax Highlighter - automatic switch between PHP, HTML, CSS, and JavaScript depending on your position!
- PHP (both version 4 and 5 are supported)
- SQL (MySQL, MSSQL 2000, MSSQL 7, Ingres, Interbase 6, Oracle, Sybase)
- HTML/XHTML
- CSS (both version 1 and 2.1 are supported)
- JavaScript
- VBScript
- Java
- C#
- Perl
- Python
- Ruby
- Smarty
PHP:
- Support for both PHP 4 and PHP 5
- Code Explorer for PHP (includes, classes, extended classes, interfaces, properties, functions, constants and variables)
- Code Completion (IntelliSense) for PHP - code assist as you type
- Code Tip (code hint) for PHP - code assist as you type
- Work with any PHP frameworks (access classes, functions, variables, etc. on the fly)
- PHP object oriented programming (OOP) including nested objects
- Support for PHP heredoc
- Enclose strings with single- or double quotes, linefeed, carriage return or tabs
- PHP server variables
- PHP statement templates (if, else, then, while…)
- Powerful PHP Code Beautifier with many configurations and profile support
- phpDocumentor wizard
- Add phpDocumentor documentation to functions and classes with one click!
- phpDocumentor tags
- Comment or uncomment with one click!
- Jump to any declaration with filtering by classes, interfaces, functions, variables or constants
Debug (PHP):
- Debug with Xdebug
- Breakpoints
- Step by step debugging
- Step into
- Step over
- Run to cursor
- Run until return
- Call stack
- Watches
- Context variables
- Evaluate
- Profiling
- Multiple sessions
- Evaluation tip
- Catch errors
Monday, March 21, 2016
Configure PayPal with Instant Payment Notification
1- Login to your PayPal Business Account
2- Go My Account -> Profile -> My selling tools
3- Click update on Website preferences
4- Choose off for Auto Return and remove the url inside
5- Choose off for Payment Data Transfer
6- Click save button
7- Go to Instant Payment Notification Preferences
8- Enable IPN message -> Pass your notification URL
9- Save
More detail about IPN
4- https://www.paypal.com/kh/cgi-bin/webscr?cmd=p/acc/ipn-subscriptions-outside Check OS and Browser Agent with PHP
The user agent string is a text that the browsers themselves send to the webserver to identify themselves, so that websites can send different content based on the browser or based on browser compatibility.
Mozilla is a browser rendering engine (the one at the core of Firefox) and the fact that Chrome and IE contain the string Mozilla/4 or /5 identifies them as being compatible with that rendering engine.
In this case I will show you how to detect the Os or Browser Agent using PHP ,
* Check OS
$agent = $_SERVER['HTTP_USER_AGENT'];
// get os
if (preg_match('/linux/i', $agent)) {
$os = 'linux';
} elseif (preg_match('/macintosh|mac os x/i', $agent)) {
$os = 'mac';
} elseif (preg_match('/windows|win32/i', $agent)) {
$os = 'windows';
}
* Check Browser Agent
if (preg_match('/Chrome/i', $agent)) {
if ($os == 'windows') {
//impleted;
} else {
//impleted;
}
} elseif (preg_match('/Firefox/i', $agent)) {
if ($os == 'windows') {
//impleted;
} else {
//impleted;
}
} elseif (preg_match('/Safari/i', $agent)) {
if ($os == 'windows') {
//impleted;
} else {
//impleted;
}
}
- Let's enjoy!Monday, August 31, 2015
Replace Multiple String with PHP
![]() |
| Replace Multiple String In PHP |
In this case you have to know a PHP function which is call "str_replace", the below code will explain you how it work.
function replace_multiple_string($search=array(),$replace="",$string="")
{
if(count($search) < 1)
{
return false;
}
else
{
return str_replace($search, $replace, $string);
}
}
Explanation:
- str_replace : Replace all occurrences of the search string with the replacement string.
Usage :
$string= "You are on_tip(and)php+website";
$search= array("_", "(", "+", ")"," ","+");
var_dump(replace_multiple_string($search,"-",$string));
Demo :
string(29) "You-are-on-tip-php-website"
Saturday, August 29, 2015
Get Mac Address With PHP
![]() |
| get mac address with php |
This post is to show you about Getting Mac Address or PC Address using PHP. This script will help you to display the Address of your computer. Based on this function I hope you will like it. Please take a look at live demo and to see your computer address.
Function (index.php)
function get_mac_address()
{
ob_start();
system('ipconfig /all');
$mycom=ob_get_contents();
ob_clean();
$findme = "Physical";
$pmac = strpos($mycom, $findme);
return substr($mycom,($pmac+36),17);
}
Explanation
-
ob_start() : Turn on output buffering -
system('ipconfig /all') : Get the ipconfig details using system commond.-
ob_get_contents() : Return the contents of the output buffer-
ob_clean() : clear or Erase output buffering.Call the function (index.php)/ Demo
<?php get_mac_address(); ?>
I hope you will share if you think it is important.


