Tuesday, December 17, 2013

Different include and require Statements

In PHP, you can insert the content of one PHP file into another PHP file before the server executes it.
The include and require statements are used to insert useful codes written in other files, in the flow of execution.
Include and require are identical, except upon failure:
  • require will produce a fatal error (E_COMPILE_ERROR) and stop the script
  • include will only produce a warning (E_WARNING) and the script will continue
So, if you want the execution to go on and show users the output, even if the include file is missing, use include. Otherwise, in case of FrameWork, CMS or a complex PHP application coding, always use require to include a key file to the flow of execution. This will help avoid compromising your application's security and integrity, just in-case one key file is accidentally missing.
Including files saves a lot of work. This means that you can create a standard header, footer, or menu file for all your web pages. Then, when the header needs to be updated, you can only update the header include file.

Syntax

include 'filename';

or

require 'filename';

Friday, November 15, 2013

Using WhatApp Throught Pidgin (Expired)

Add WhatApp repo to your list

deb http://ppa.launchpad.net/whatsapp-purple/ppa/ubuntu quantal main
deb-src http://ppa.launchpad.net/whatsapp-purple/ppa/ubuntu quantal main


Update package:

sudo apt-get update

Install WhatApp pluggin:

sudo apt-get install pidgin-whatsapp

Or you can download manually the WhatsApp Plugin here:

http://web.davidgf.net/nightly/whatsapp-purple/
For 32bit choose 386 folder
For 64bit choose X64 folder


Copy files with extension .so to folder:

~/.purple/plugins/

Your pidgin should have been WhatsApp

Next, We use third party to get WhatApp username and password

# apt-get install python python-dateutil python-argparse
# wget https://github.com/tgalal/yowsup/archive/master.zip
# unzip master.zip
# cd yowsup-master/src
# cp config.example yowsup-cli.config


Edit yowsup-cli.config, cc = Your country code without (+), phone = your phone number with country code, id and password leave blank.

# vim yowsup-cli.config
cc=62
phone=628578945612
id=
password=


Change permission

# sudo chmod +x yowsup-cli

Request code

# ./yowsup-cli --requestcode sms --config yowsup-cli.config
status: sent
retry_after: 3605
length: 6
method: sms


Or you can request code via website

http://whitesoft.dyndns.org:2222/whatsapp_sms

After you receive an code, Then confirm your code. 123-456 is an code

# ./yowsup-cli --register 123-456 --config yowsup-cli.config
status: ok
kind: free
pw: S1nBGCvZhb6TBQrbm2sQCfSLkXM=
price: 0,89
price_expiration: 1362803446
currency: EUR
cost: 0.89
expiration: 1391344106
login: 628578945612
type: new


"login:" is your username. "pw:" is your password.
try to login via pidgin.

Note:
To avoid crashes on the client side, make your status to "away" do not use "available"crashes occur usually on android device.

Adding extra Repositories on Ubuntu

sudo vim  /etc/apt/sources.list

add your repo to new line

Example of repo:

deb http://ppa.launchpad.net/whatsapp-purple/ppa/ubuntu quantal main
deb-src http://ppa.launchpad.net/whatsapp-purple/ppa/ubuntu quantal main


Once you are done adding the repositories, you’ll need to run this command:

sudo apt-get update

Thursday, November 14, 2013

Running DBus in Crontab

Just create an sh file to execute your script. example chat.sh. See below:

#!/bin/bash
xhost +
export DBUS_SESSION_BUS_ADDRESS=$(cat /home/iben/.dbus/session-bus/f49d2a1187871a80e2a3bb640000000a-0|grep unix|cut -d= -f2-4)

ps -ef | grep -v grep | grep chat.php
# if not found - equals to 1, start it
if [ $? -eq 1 ]
then
/usr/bin/php /home/iben/www/tes/dbus/chat.php&
else
echo "eq 0 - chat.php found - do nothing"
fi
Note:
xhost + is required

export DBUS_SESSION_BUS_ADDRESS=$(cat /home/iben/.dbus/session-bus/f49d2a1187871a80e2a3bb640000000a-0|grep unix|cut -d= -f2-4) ==> is required to inform cron of session location.

f49d2a1187871a80e2a3bb640000000a-0 ==> is a long name that is different with your. Usually have pattern like *a-0, a file in directory /home/username/dbus/sessiom-bus/*a-0. Find your.

Sintax after it is your own script. Here I use script to check existing process. if not exist then run the php script. Else don't do anything.

chat.php is a script that use DBus class.

Simply add to cron like this:
* * * * * sh /home/iben/www/tes/dbus/chat.sh > /home/iben/www/tes/dbus/chat.log

It will check process every minute. It better than use 'php flock'.

Wednesday, November 13, 2013

How To :: Install PECL on Ubuntu

Hw To :: Install PECL on Ubuntu

sudo apt-get php-pear php5-dev
sudo pear install PEAR

How To :: Install DBus for PHP on Ubuntu

First you need to install pkg-config package.sudo apt-get install pkg-configNow you need to install DBus package. This will manage all background actions needed by the PHP extension.sudo apt-get install dbus libdbus-1-dev libxml2-devNow we can install the PECL DBus extensionsudo pecl install DBus* if you do not have PECL installed click here * if you get an error like "Failed to download pecl/Dbus within preferred state stable, latest release is version 0.1.1, stability 'beta', use ..... install failed" you need to install the version it says it's the last. For example :sudo pecl install DBus-0.1.1add the extension to PHPecho -e "; configuration for php DBus module\nextension=dbus.so"| sudo tee -a /etc/php5/conf.d/dbus.ini
Note:
If you update your PHP VERSION or find error like this :
PHP Warning:  PHP Startup: dbus: Unable to initialize module
Module compiled with module API=20090626
PHP    compiled with module API=20100525

Or you find error like this :
Can not load dinamic library... blablablabla

You can resolve with this:
sudo pecl install -f DBus

Friday, October 25, 2013

Make VIM as default editor in terminal

  • cd (cd to your home directory)
  • vim .bashrc (Edit bashrc file)
  • add this export EDITOR=vim to bottom of lines
  • This will affected to new terminal