Thursday 4 August 2022

Scraping HTML using PHP

 To read HTML files using PHP, you can use the library simple dom html


You can download from - https://sourceforge.net/projects/simplehtmldom/

Thursday 4 December 2014

How to find execution time for a script in PHP

if your are a PHP dev and you execute php scripts to test time taken, the following code can help you


microtime — Return current Unix timestamp with microseconds



[php]
//Start time
$time_start = microtime(true);

// Sleep for 1 sec
sleep(1);

//Execution of your script

//End time
$time_end = microtime(true);

//Time taken
$time = $time_end - $time_start;

echo "Time taken is $time seconds\n";

[/php]

Hope this will be useful in your application
Ref

Tuesday 18 February 2014

How to add assets in CodeIgniter

When you are creating a Web Application with CI, you work with assets

you can create a "assets" folder in the root folder

To activate it

Step 1: Create Application Helper

application/helpers/utility_helper.php
function asset_url(){
   return base_url().'assets/';
}

Step 2: application/config/autoload.php:
$autoload['helper'] = array('url','utility');

After this you can very well use asset_url(); with in your application
 Ref

How to remove index.php from url in code igniter

Create a .htaccess file in root directory and

Copy paste this code
RewriteEngine on

RewriteCond $1 !^(index\.php|assets|robots\.txt)

RewriteRule ^(.*)$ index.php/$1 [L]
where assets is the folder in the root directly containing all your assets Ref

Wednesday 31 July 2013

What is SQL Injection and How to avoid it?

SQL injection happens if the user input is not properly validated

This is just to play around with the database queries


To Avoid SQL Injection


  • Encrypt sensitive data.
  • Access the database using an account with the least privileges necessary.
  • Install the database using an account with the least privileges necessary.
  • Ensure that data is valid.
  • Do a code review to check for the possibility of second-order attacks.
  • Use parameterised queries.
  • Use stored procedures.
  • Re-validate data in stored procedures.
  • Ensure that error messages give nothing away about the internal architecture of the application or the database.



Difference between PHP4 and PHP5



Advantages of PHP5

Static Methods and Variables

Visitbility
Public , Private and Protected

Abstract Classes

Interfaces

Magic Methods

Final Keyword

__autoload Function

Type Hinting

Exceptions



Ref: http://www.webmaster-talk.com/php-forum/78717-differences-between-php4-and-php5.html