Wednesday, 4 January 2017

FIll Zeroes before the Number in PHP


 function zerofill ($num, $zerofill = 10) {
                        return str_pad($num, $zerofill, '0', STR_PAD_LEFT);

}
                   
                    

 echo  zerofill (2,5);

output: 00002

in zerofill function, just put the number in the first parameter, and in the second parameter, just add the number of zeros to be fill.

Monday, 2 January 2017

Server to Server File Transfer using Secure Copy in Linux


We will be using scp command for transferring files from two remote computer

scp -r yourfoldername root@destination_ip:/home/

 (after initiating this command, you will be prompt to enter the root password of the destination ip)


in this command you are transferring all content of "yourfoldername" recursively to destination_ip in home directory path.

if you want to transfer a non folder file you can use this command

scp filename.gz root@destination_ip:/home/


take note:
you can change /home/ to the path you want to place your source file.

Change MySql Root Password



UPDATE user SET Password=PASSWORD('xxx') WHERE User='root'; FLUSH PRIVILEGES; exit;

just execute this query and replace xxx with your new password.

Wednesday, 28 December 2016

MySQL Insert record with condition



INSERT INTO paid_order_id(order_id,custom_value) SELECT order_id,'custom value' from orders
WHERE order_status = 'Paid';

in this example, you create a table name "paid_order_id" and insert all order_id from table orders but only with paid status.

Run PHP and MySQL in your Android Phone



To run PHP in your android phone you need to have an Apache Service running 
you can download 
https://play.google.com/store/apps/details?id=com.andi.serverweb&hl=en
or Search for Bit WebServer in Google Playstore
it supports 

LIGHTTPD as Web Server ,
- PHP as PHP Server ,
- MYSQL as MySQL Server ,
- MSMTP as SMTP Client



after installing the application, just start LIGHTTPD and mysql and put your website in www folder in root directory of your android phone.

you can also access phpmyadmin and import your mysql database. 


this will run your php website in your android phone :)

if you are using codegniter and using mod_write there's lighthttpd configuration in the app. just enter this code 

 url.rewrite = (
      ".*\.(js|ico|gif|jpg|png|swf|css|html)$" => "$0",
      "^/(.*)$" => "index.php/$1"
 )


to enable ur rewrite.


htaccess redirect www to non-www


Just paste the below code in your .htaccess file to redirect www to non-www URL
make sure that mod_rewrite module is enable in your server.



RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
 
 

htaccess redirect to non-www




Just paste the below code in your .htaccess file to redirect non-www to www URL
make sure that mod_rewrite module is enable in your server. 

 
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]