affiliate_link

Friday, June 8, 2012

JSON Q&A

1. What is JSON?
JSON is a light weight, text based (human readable) open format used for data transformation.
JSON is language independent with parsers available in many languages
JSON is often used for serializing and transmitting structured data over a network connection.
Hence it is used as an alternative to XML    

2. Why JSON over XML?
 JSON
 (i)  Is lighter and faster than xml
 (ii) Objects are typed
 (iii) Data types in JSON can be number, string, bool, arrays whereas in xml only strings


3. How is JSON structured?
JSON is structured as a collection of name value pairs



Wednesday, May 30, 2012

PHP Q&A

1. How many are PHP super global variables?
(a)  $_REQUEST
(b)  $_POST
(c)  $_GET
(d)  $_COOKIES
(e)  $_SERVER
(f)   $_FILES
(g)  $_ENV

2. How can we get images properties like type, size, width, height?
For image type we can use           exif_imagetype()
Image size use                             getimagesize()
Image width                                 imagesx()
Image Height                               imagesy()

3. Get browser properties using PHP?
echo $_SERVER['HTTP_USER_AGENT'];

4. How many ways we can pass data between two pages using php?
(a) Register data in sessions
(b) Use cookies
(c) Pass value as GET or POST

5. How to make a script support multiple languages?
Set charset = UTF-8

6. What is the difference between Echo and Print in PHP?
Echo and print are more or less the same both outputs to the browser.
Difference is print() only takes one argument and returns true on successful printing
Echo is slightly faster than print

7. How to prevent hacking in PHP?
(a) Set Register_globals to OFF to prevent form injection with malicious data
(b) Set Error Reporting to E_ALL to show all error messages
(c) Validate input using htmlentities(), strip_tags(), utf8_decode() & addslashes()

8. What is the difference between Notify URL and Return URL using Paypal?
Notify URL
Notify URL is used by PayPal IPN for sending transaction information 

Return URL
The url to which user is returned after successful payment


9. What is ob_start()?
ob_start() turns on the output buffering. When buffering is ON any output sent from server will be stored in a buffer until ob_end() is called or script ends.
It eliminate Headers already sent problem


Monday, May 28, 2012

How to set dropdown value using jquery?

If you know the value you can set it like this 
 
$("#myddl").val("somevalue");
 
Setting through index
 
$("#mydropdownlist").attr('selectedIndex', 0);
 

Wednesday, February 15, 2012

Altering table adding columns

Alter Table TableName

Add    [ColumnName1] [float] NULL,
           [ColumnName2] [nvarchar](50) NULL,
          

Tuesday, February 14, 2012

Custom 404 Error Page

Write in .htaccess

ErrorDocument 404 /404-error-page.html

Change Where  404-error-page.html to your error page

Disallow folders using Robots.txt

User-agent: *
Disallow: /folder1/
Disallow: /folder2/

Where folder1 & folder2 are the folders which should be hidden from the search engines

Wednesday, January 11, 2012

Mysql Database Backup using Cron Job



mysqldump -h [host] -u[username] -p[password] [dbname] > /[documentroot]/db-backups/dump.txt


Replace [host] with your host name mostly localhost 
[username] with database username
[password] with database password
finally [documentroot] with your FTP root