Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, 21 March 2016

LOAD DATA INFILE statement in MySQL

Your script stops while fetch data from txt/csv file? Here is a MySQL feature to make this task faster. "LOAD DATA INFILE" statement::

The LOAD DATA INFILE statement reads rows from a text/CSV file into a table at a very high speed.

To write data from a table to a file, use SELECT ... INTO OUTFILE. To read the file back into a table, use LOAD DATA INFILE. The syntax of the FIELDS and LINES clauses is the same for both statements. Both clauses are optional, but FIELDS must precede LINES if both are specified.

SYNTAX to fetch data from CSV file:

$FILE_PATH = "test.csv";
$TABLE_NAME = "tablename";
$TABLE_FIELDS = "name,address";

'LOAD DATA LOCAL INFILE "$file_path"
            INTO TABLE "$table_name"
        FIELDS TERMINATED BY ","
        OPTIONALLY ENCLOSED BY "\"
        LINES TERMINATED BY "\n"
($TABLE_FIELDS)';

In the above example, your CSV file must contains 2 fields name and address and line terminated by "\n".

For more reference
http://dev.mysql.com/doc/refman/5.7/en/load-data.html

Monday, 14 March 2016

Register Globals (register_globals) in PHP

Register Globals (register_globals)

Secure you application by disabling register_globals variable,

register_globals
was meant to help rapid application development. 


Any URL which includes a query string,the register_globals statement allows us to access the value of variable with $variable instead of $_GET['variable'] automatically.

This might be useful for us, but all variables in the code now have this property, and we can now easily get into PHP applications that do not protect against this unintended consequence.

If you have added below code into your login page,

if(!empty($_POST['user_name']) && $_POST['user_name'] == 'abc' && !empty( $_POST['password'] ) && $_POST['password'] == "abc123")
{
    $valid = true;
}
if($valid==true) { $show_user_pages = 1; }

If the application is running with register_globals ON, a user could just place valid=1 into a query string, and would then have access to whatever the script is running.


So it is better to running application with register_globals OFF.

We cannot disable register_globals from the script side, but we can use an .htaccess files or change php.ini file to do this.

Disabling with php.iniregister_globals = Off


Disabling with .htaccess
php_flag register_globals 0


Enjoy with secure php script with register_globals Off !!