HTTP_RAW_POST_DATA on PHP5.3.x issue

HTTP_RAW_POST_DATA on PHP5.3.x issue
issue on HTTP_RAW_POST_DATA was empty set on process

Problem is :

Script receives gzipped data from a desktop application via POST, which it retrieves and processes from $HTTP_RAW_POST_DATA. In PHP 5.2.16 (ISAPI), $HTTP_RAW_POST_DATA is correctly being populated with the expected binary data. After upgrading to PHP 5.3.9 (FastCGI), $HTTP_RAW_POST_DATA is not defined. How can I get the data?

Answer :

The docs regarding $HTTP_RAW_POST_DATA state that it 'is not available with enctype="multipart/form-data"', but I'm not using that content type. (Recall that the same code works fine under PHP 5.2, so content type would have been a problem then, too.)

When I enabled the always_populate_raw_post_data ini directive, nothing changes. phpinfo() reports that setting as "On", but the variable is still not being set.

The docs also suggest that the preferred method to obtain this data is to read it from the php://input stream instead. I tried that as follows:

$HTTP_RAW_POST_DATA = file_get_contents('php://input');

but the script just hangs on that line, presumably because it's waiting for data (i.e., no End-Of-File sent). Even if I limit the maxlength to a value as small as one byte as follows, it still hangs.

$HTTP_RAW_POST_DATA = file_get_contents('php://input', false, null, -1, 1);

The only time it doesn't hang on that line is when I set the maxlen to 0, which means it doesn't try to read anything but also isn't helpful. :-)

If $HTTP_RAW_POST_DATA won't populate when I force it to, and I can't get anything from php://input, how can I get the data?

Is the fact that php://input is apparently empty indicative of a difference between ISAPI and FastCGI? I haven't read anything suggesting that raw POSTs behave differently or are lost under FastCGI.

Suggest :

if ( !isset( $HTTP_RAW_POST_DATA ) ) {$HTTP_RAW_POST_DATA =file_get_contents( 'php://input' ); //echo "WOke";

Installing and Configuring Freeradius + MySQL and Daloradius + MySQL on Ubuntu Server 11.04 for Mikrotik Hotspot/PPoE/PPTP (Tested on VirtualBox)

Installing and Configuring Freeradius

The first step is to Install Freeradius (ensure you already update your apt with apt-update)
$sudo apt-get install freeradius 
 * Starting FreeRADIUS daemon freeradius                                 [ OK ] 
Setting up freeradius-utils (2.1.10+dfsg-3build2) ...

Then prepare the database for freeradius. Create database radius and assign username and password for accessing it. 

# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 51
Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database radius; 
mysql> grant all on radius.* to radius@localhost identified by "thepassword";
Query OK, 0 rows affected (0.00 sec)

The next step was to insert the database schema and I realized that I could not find the database scheme in /etc/freeradius.

Obviously I should install freeradius-mysql package first. 

#apt-get install freeradius-mysql
Setting up freeradius-mysql (2.1.10+dfsg-3build2) ...
 * Reloading FreeRADIUS daemon freeradius                                [ OK ] 

Then insert the database scheme 

# mysql -u root -p radius < /etc/freeradius/sql/mysql/schema.sql 
Enter password:
# mysql -u root -p radius < /etc/freeradius/sql/mysql/nas.sql 
Enter password: 

Now we try to insert new user for testing purpose in database. 

# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 72
Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use radius;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> INSERT INTO radcheck (UserName, Attribute, Value) VALUES ('sqltest', 'Password', 'testpwd');
Query OK, 1 row affected (0.04 sec)

mysql> exit

The next step is we need to configure the Freeradius files. 

Edit /etc/freeradius/sql.conf file. Setting database type, login and password that we already setup before.

# vim /etc/freeradius/sql.conf
  database = mysql
  login = radius
  password = thepassword

  readclients = yes

Then edit the /etc/freeradius/sites-enabled/default file

# vim /etc/freeradius/sites-enabled/default 

    Uncomment sql on authorize{}
    # See “Authorization Queries” in sql.conf

    Uncomment sql on accounting{}
    # See “Accounting queries” in sql.conf

    Uncomment sql on session{}
    # See “Simultaneous Use Checking Queries” in sql.conf

    Uncomment sql on post-auth{}
    # See “Authentication Logging Queries” in sql.conf
Then we edit /etc/freeradius/radiusd.conf file

# vim /etc/freeradius/radiusd.conf 

  #Uncomment #$INCLUDE sql.conf
  $INCLUDE sql.conf

To test our configuration, first we must stop the freeradius service (if already running) 
# /etc/init.d/freeradius stop
 * Stopping FreeRADIUS daemon freeradius                                 [ OK ]

Then run this command to run freeradius in debugging mode. If there is no error, you are good to go.
#freeradius -X

On a new shell or window we tested the connection

$ radtest sqltest testpwd localhost 18128 testing123
Sending Access-Request of id 65 to port 1812
User-Name = "sqltest"
User-Password = "testpwd"
NAS-IP-Address =
NAS-Port = 18128
rad_recv: Access-Accept packet from host port 1812, id=65, length=20

The test running well with Accept response from the server.

To enable Mikrotik device to access our server we need to add client in clients.conf file.

#vim /etc/freeradius/clients.conf

client {

        secret = testingpassword
        shortname = testing
        nastype= mikrotik

*note: we need to stop freeradius -X and then running it again to test our configuration

Update (Jan 27, 2013):  If we want to add specific value for Mikrotik, we need to add mikrotik dictionary

#vim /etc/freeradius/dictionary 

Then add this line below

$INCLUDE  /usr/share/freeradius/dictionary.mikrotik

Mikrotik Configuration

We need to configure our Mikrotik devices to use our new radius server.  We need to login to Mikrotik device and configure the radius in Radius menu. 

Below image is an example of our configuration. 

*Note: we increase timeout settting to 3000ms to enable invalid login notifications. (not working with default 300ms)
You can setting Mikrotik Hotspot using that Radius if you want, or can use another hotspot software like easyHotspot

Daloradius Installation 

First, we need to download daloradius file 


Rename and extract the file 

# tar xvfz daloradius-0.9-9.tar.gz
# mv daloradius-0.9-9 daloradius

Move the file to the web server directory. In this case I use apache on Ubuntu so the location is at /var/www

# mv daloradius-0.9-9 daloradius
# mv daloradius /var/www

Then we need to setup the database. Because already setup the freeradius using MySQL, so we don't need new database. All we need to do is to import the daloradius scheme into our existing radius database.

# cd /var/www/daloradius/contrib/db
# mysql -u root -p radius < mysql-daloradius.sql

After database successfully altered, we need to configure the daloradius setting.

#vim /var/www/daloradius/library/daloradius.conf.php

Change the database password 

$configValues['CONFIG_DB_PASS'] = 'thepassword';

Then we can try to access daloradius using http://ipaddressoftheserver/daloradius

*Note: In my installation, i had a problem because I didn't have php5-gd php-pear and php-db packages installed on my Ubuntu server. 

To deal with this problem you can install the packages using

# apt-get install php5-gd php-pear php-db 

If some time going wrong..cek this

Failed binding to authentication address * port 1812: Address already in use
/etc/freeradius/radiusd.conf[240]: Error binding to port for port 1812
ps aux | grep free
ps ax | grep radius
check for the process already running.
kill -9 PID
then start radius in debug mode.
/usr/sbin/freeradius -X you probably have one started manually and one from init.d, and they are arguing over port access.
After all, when you kill the PID.
Just start the freeradius from demon.
/etc/init.d/freeradius start
Start normally.
Now to confirm everything is working fine, restart the server.
/etc/init.d/freeradius restart
If there is any issue, Comments here.


Sublime Text 3 perfect PHP development set-up

Sublime Text 3 perfect PHP development set-up

This is follow-up arti­cle to Sub­lime Text 2 per­fect PHP devel­op­ment set-up. I decided to write this updated ver­sion, because from some time now Sub­lime Text 3 is out there. Maybe it is still offi­cially beta, but works pretty sta­ble and I’m using it for few months now.

This list is almost the same as in pre­vi­ous arti­cle — most of plu­g­ins I used with ST2 have been updated in order to work with ST3 and I stopped using few of them, so they are out. I’m kinda lazy, so some of descrip­tions are copy-pasted from pre­vi­ous article ;)
Any­way, here is the list:
  1. Pack­age Con­trol (
    Thanks to this lit­tle piece of soft­ware all other plu­g­ins are eas­ily installed.
  2. Sub­lime­CodeIn­tel (
    This is pack­age I use all the time. Its job is to pro­vide hints related to func­tion, object, vari­able etc. names. It also hints what meth­ods and para­me­ters are avail­able in objects/classes. It’s based on Komodo CodeIn­tel and some­times it has some prob­lems work­ing at all. But most of the time it rocks :)
  3. Sub­limeLin­ter (
    This pack­age does full-time job for me — it con­stantly watches what I write and instantly lets me know if some­thing is not OK, for exam­ple I for­get semi-colon or brackets.
    From ver­sion 3 and up, Sub­limeLIn­ter has become mod­u­lar. This means, that you have to install main pack­age first, and then plugin/module for every lan­guage you need sup­port for. Each plu­gin has it’s own set of require­ments, so please make sure you read them thoroughly.
    For PHP + JavaScript devel­op­ment I’m using:
  4. Side­BarEn­hance­ments (
    Pro­vides great new options when right-clicking on side­bar ele­ments (files/folders). Very convenient.
  5. VCS Gut­ter (
    Lately I don’t imag­ine work­ing with­out this one. Every day I use Git and Mer­cu­r­ial and this plu­g­ins gives me real-time infor­ma­tion about what was changed (or added/removed) in cur­rent file using sym­bols in left-hand edit win­dow gutter.
  6. SFTP, paid (
    Great pack­age enabling very com­fort­able use of SFTP, FTP and FTPS. It sup­ports remote fold­ers brows­ing, edit­ing and syn­chro­niza­tion between local and remote files. Also reg­u­lar upload, down­load pn save or file open.
  7. Tor­toise (on Win­dows only) (
    I use it as a com­ple­men­tary pack­age to Side­Bar­Git if I’m work­ing in Win­dows envi­ron­ment. It doesn’t have so many fea­tures but those what it pro­vide are very help­full and intuitive.If you like Tor­toise Git but you are work­ing on Linux you might want to check out Rab­bitVCS. It isn’t inte­grated with ST2, but it pro­vides com­fort­able right-mouse-click Git GUI.
  8. sublime-github (
    Every devel­oper should use code snip­pets of some kind. I use Gist pro­vided by GitHub and this pack­age enables me to use them instantly (save/paste).
  9. Tag (
    It is fine plu­gin, but now ST3 sup­ports tag match­ing, so I don’t need it any more.
  10. Php­Doc (
    Great plu­gin aid­ing writ­ing doc­u­men­ta­tion docblocks for PHPDocumentor.
  11. Phpcs (
    This pack­age adds sup­port for PHP_CodeSniffer to ST2. It checks if you code is writ­ten accord­ing to one of the stan­dards. Just pick one: Zend, PEAR.. and more :) Check out PHP_CodeSniffer web­site for con­fig­u­ra­tion details.
  12. Trail­ing­Spaces (
    Small hor­ror of every code — empty spaces at lines ends, at the end of file. Espe­cially trou­ble­some if you are work­ing on the code with other devel­op­ers, who might use dif­fer­ent editors/IDEs which might inter­pret them (empty spaces) differently.
  13. Brack­etHigh­lighter (
    Same sit­u­a­tion as with Tag plu­gin. In my every­day cod­ing ST3 bracket high­light­ing capa­bil­i­ties of ST3 are good enough. It is still great plu­gin though.
  14. Sub­lime Func­tion Name Dis­play (
    Dis­plays in bot­tom bar name of a func­tion (or method) in which our cur­sor is placed. Sim­ple and helpful.
  15. Ter­mi­nal (
    Using Git or maybe some PEAR pack­ages you might need to switch to con­sole from time to time and do some magic. Maybe use Zend Tool or “bake” some­thing ;) It’s just what this plu­gin is for.
  16. Xde­bug Client (
    Lately my favorite Xde­bug client for ST3. Works great and allows to use all of Xde­bug debug­ging capabilities.
Few sup­port­ing pack­ages. I con­sider them optional, but they come in handy:
  1. LineEnd­ings (
    Nice to have plu­gin if you are work­ing with other devel­op­ers using Win­dows and Unix/Linux machines. It takes care of dif­fer­ent (invis­i­ble) line end­ing char­ac­ters in those systems.
  2. Sass (
    This one comes in handy when work­ing with Sass files. Syn­tax high­light­ing and so on.
  3. Plain­Tasks ( added thanks to Virion’s com­ment
    Great tool for every­one who like to have their tasks orga­nized, flex­i­ble with many great features.
  4. Sub­limerge ( thanks to Virion’s com­ment
    Diff tool on steroids. Ideal for every­one who has to do a lot with merg­ing, espe­cially use­ful when it comes to large files.
  5. Dash­Doc ( only)
    This one is for Mac users only and only for those who have Dash installed, but I really rec­om­mend it. Dash pro­vides access to docs of almost every major library, frame­work etc. and so much more! With this plu­gin you can access it directly right from Sub­liem Text code win­dow with key­board short­cut. It really speeds up coding.
That’s it for now. I might come back and some­thing later, but this is my set-up and works great for me.


How to create and execute JAR file in Java – Command line Eclipse Netbeans

Creating JAR file in java from command prompt is always been little tricky for many of us even if IDE like Netbeans and Eclipse provide support to export java program as JAR file simply because we don’t create jar often and not familiar with manifest file or jar command as whole. JAR file in Java is a kind of zip file which holds all contents of a Java application including Class files, resources such as images, sound files and optional Manifest file. JAR stands for Java Archive and provides a platform independent deliverable for java programs, libraries and framework. you can execute same jar file in any operating system e.g. Windows 7, windows 8, Macintosh or Linux. Apart from platform independence and standard delivery method jar file also provides compression of contents which results in faster download if you are downloading java program from internet specially in case of mobile devices where you install Java program by OTA. In this article we will some JAR command examples and learn how to create and execute jar filehow to view contents of jar file from command prompt and Eclipse and Netbeans.

How to create jar file in Java form command prompt

Example to create and execute JAR file in Java from Command line Eclipse and Netbeansjar command in Java allows you to create jar file from command prompt, what is required is that you must have jar command included in System PATH variable. you can check this by typing "jar" in command prompt if it doesn't throw error as "jar is not recognized as an internal or external command" they you are ready to go. When you create jar file in Java, command also creates Manifest file which is optional and you can control whether to create it or not by jar command line options, but if you want to create executable jar file they you must need Manifest file which we will discuss in further sections. Now here is jar command example to create jar file from command prompt, this will work both in windows and Linux operating system.

JAR command Examples in Java

javin@localhost:~/Java jar -cvf HelloWorld.jar HelloWorld.class
added manifest
adding: HelloWorld.class(in = 450) (out= 311)(deflated 30%)

This command will crate Helloworld. jar which contains Helloworld.class file. this will also create manifest file but without Main-Class entry as shown below:

javin@localhost:~/Java cat MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.6.0-beta2 (Sun Microsystems Inc.)

This jar can not be executed and you will get error when you try to run this jar file:

javin@localhost:~/Java java -jar HelloWorld.jar
Failed to load Main-Class manifest attribute from HelloWorld.jar

You just need to provide Main-Class entry to get rid of this error which we will see in coming Section.

How to Create an executable JAR file in Java

To create an executable JAR in Java, you need to provide a manifest file and include your Main Class in Manifest. When you create jar file , jar command also creates manifest file inside META-INF as MANIFEST.MF but doesn't create Main-Class entry which is required for executable jar file. You can create executable jar file in Java by two ways either provide a self created Manifest file or specify entry point using "-e" jar option. If you provide external Manifest file than you need to use jar -m option to include that manifest file inside jar. Let's see example of both ways to create executable jar file in Java.

Executable JAR File Example with External Manifest

1.Create MANIFEST.MF file by using any text editor e.g. notepad in windows or Vim in Unix and add following entry in file, remember last line must end with either new line or carriage return:

Manifest-version: 1.0
Main-Class: HelloWorld

Important thing to remember is that we need to specified full classified class name here. suppose if our main class was inside com/example/HelloWorld than we should have to specify com.example.HelloWorld here, don't put .class extension here its not required. Apart from specifying Main-Class you can also specify Java Classpath in Manifest file which is important if your application is depended on external library jars. "Classpath" entry supersede both -cp and CLASSPATH environment variable. to learn more see How ClassPath works in Java.

2.Execute following jar command to create executable jar

javin@localhost:~/Java jar -cvfm HelloWorld.jar MANIFEST.MF HelloWorld.class
added manifest
adding: HelloWorld.class(in = 450) (out= 311)(deflated 30%)

here -m is used for including manifest file and remember specify name of manifest file after jar name. now you have an executable jar file in java which you run by command specified earlier.

Creating Executable JAR File By entry point

This seems to me an easy way to create executable jars in Java, as you need not have to create manifest file explicitly and it will be create by jar command itself along with Main-Class entry. What you need to provide is a new jar option "-e" and you main class name while running jar command. here is example of jar command with entry option:

javin@localhost:~/Java jar -cvfe HelloWorld.jar HelloWorld HelloWorld.class
added manifest
adding: HelloWorld.class(in = 450) (out= 311)(deflated 30%)

jar -e for entry point and entry point or main class name should come after jar file name and before directory or file needs to be included in JAR. You can now run your executable jar file by issuing "java -jar" command as shown in following example:

javin@localhost:~/Java java -jar HelloWorld.jar
Executing Java Program from JAR file

How to execute Java Program from Jar file

Executing jar program from jar archive is very easy one thing required is jar must be executable and must have Main-Class entry in MANIFEST.MF file. here is a Java command example for running java program from jar file:

javin@localhost:~/Java java -jar HelloWorld.jar
Executing Java Program from JAR file

here we have specified jar file name with -jar option and it will run main class declared as “Main-Class” attribute in manifest file.

How to view contents of a JAR file in Java

jar command in Java allows you to view files and directories inside of a jar file without extracting or unzipping original jar. "-t" jar option is used to list files from jar archive as shown in jar command example below:

javin@localhost:~/Java jar -tvf HelloWorld.jar
0 Wed Dec 07 22:36:12 VET 2011 META-INF/
95 Wed Dec 07 22:36:12 VET 2011 META-INF/MANIFEST.MF
450 Wed Dec 07 21:36:04 VET 2011 HelloWorld.class

here "-t" for listing and "-v" and "-f" for verbose and jar file name.

How to extract contents of JAR File

use jar option "-v" for extracting files form JAR files as shown in jar command example below:

javin@localhost:~/Java jar -xvf HelloWorld.jar
created: META-INF/
inflated: HelloWorld.class

here -x for extracting , -v is for verbose and -f specify jar file name.

How to create jar file in Eclipse

Creating JAR file in  Eclipse IDE is a cakewalk once you know the process. here is step by step guide of creating JAR file from Eclipse IDE: In Jar file main class is specified as “Main-Class” attribute inside manifest file and used as program entry point if you double click on JAR or run jar from java command.

1) Select Project for which you want to create jar file.
2) Go to File Menu and select Export
3) Expand Java folder and select JAR file

Now you just need to click next and follow instruction as displayed. you can select what contents you want to export to jar file and specify Main Class entry as well. If you like Eclipse IDE then you may like my earlier post on eclipse as well e.g. Java debugging tips in Eclipse and  How to setup java remote debugging in Eclipse.

How to create jar file in Netbeans

In Netbeans to create jar file you need to build the project which execute project ant file and creates JAR file inside dist folder. You can go on properties of project and specify main class there which will be run when you run the project and same will be used to create “Main-Class” attribute in JAR file.

jar is not recognized as an internal or external command

if you get this error while executing jar command from command prompt in Windows or Unix it means your Java Path is not set properly. JAR command is a binary which resides in JDK_HOME/bin folder where JDK_HOME is JDK installation directory. In order to use jar command from command prompt this bin folder must be in your System's PATH variable. Don't worry if its not there in PATH you can check this link to Set PATH for Java in Windows and Unix.It shows how you can do it in both Windows and Unix. Once your PATH is property set, you will see following output when you execute jar command from command  line:

javin@localhost:~ jar
Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
-c  create new archive
-t  list table of contents for archive

and now you are ready to use jar from command prompt.

WAR and EAR -  related JAR like fies in Java

WAR file
WAR file in Java stands for Web application archive and it is used to package a Java application together you can package all your ServletJSP, CSS, images, html in one WAR file and then deploy it to any Java web or application server like Tomcat, Weblogic or webshere. WAR files provide a clean and faster way to package and deploy Java web application just like JAR file provides for core java apps. Since WAR file also compacts resources inside it is comparatively download faster than downloading individual components.

EAR file
EAR file stands for Enterprise Java Archive and used to package an Enterprise Java application, like earlier WAR and JAR file. What separates EAR archive to WAR file is inclusion of Enterprise Java Beans(EJB). EAR file contains all web resources including Servlet, JSP, html, javascript, css, images along-with EJB. You can not deploy EAR files into web servers like Tomcat because it doesn't support EJB and can only be deploy-able in Application servers like WebSphere or Weblogic.

JAR File format in Java

Few words about java jar file format, its similar to zip format and use .jar extension. you can open JAR file in windows by using either winzip or winrar zip utilities.

That’s all on how to create jar file from command line, Eclipse, Netbeans. How to extract contents, how to run Java program from jar file etc. Let me know if you face any issue while creating JAR file in java.

Read more: