Home » PHP (page 2)

PHP

Global Ajax Event Handlers

These following Global Ajax Events to be called at the time of initialization ,completion,success,send..etc. These type of events are triggered on each Ajax request, if the global property in jQuery.ajaxSetup() is true . ajaxComplete():This global event to be triggered when Ajax requests complete. .ajaxError(): This global event to be triggered when Ajax requests complete with an error .ajaxSend(): This global ...

Read More »

Advanced method to check the mime type of file in php

Usually code is if ($_FILES['input_field_name']['type'] == 'image/jpeg') { //some code } but it is not fully validating the file types(mime). The following code will output the correct file type and avoids the security vulnerabilities of php. $phpfileInfo = new finfo(FILEINFO_MIME_TYPE); $PhpfileContents = file_get_contents($_FILES['name_of_input_field']['tmp_name']); $MimeFileType = $phpfileInfo->buffer(PhpfileContents);

Read More »

How to Check Expired Sessions using jQuery Ajax and PHP

We can achieve using the php and ajax.The following ajax call execute in every 10 seconds to check the status of session.If it expired the user redirected to seesionout page. Ajax call in every 10 seconds   var check_current_session; function CheckForCurrentSession() { var strSession=”check_current_session=true”; jQuery.ajax({ type: “GET”, url: “check_current_session.php”, data: strSession, cache: false, success: function(result){ if(result== “Y”) { alert(‘Your session ...

Read More »

Major security issues facing by the websites

  Vulnerabilities Severity 1) Cross Site Scripting HIGH 2) File Upload Vulnerability HIGH 3) Directory Listing Vulnerability HIGH 4) Unencrypted Login Pages HIGH 5) Session Hijacking HIGH 6) Cross Site Request Forgery(csrf) HIGH 7) Weak Captcha Implementation MEDIUM 8) Cross Frame Scripting(css) MEDIUM 9)Internal Error Handling MEDIUM 10)Cookies are not marked as HTTPOnly LOW Recommendations • Random Tokens should be ...

Read More »

Add multiple products to Paypal Cart with One Click

Paypal is a payment gateway used in number of websites in world wide.We can post shopping cart info  to paypal from the website The following code shows the syntax of code used to post multiple cart items to paypal <form id=”paypalform” action=”https://www.paypal.com/cgi-bin/webscr” method=”post” name=”paypal_auto_form”> <input name=”rm” type=”hidden” value=”2″ /> <input name=”cmd” type=”hidden” value=”_cart” /> <input name=”upload” type=”hidden” value=”1″ /> <input ...

Read More »

Find Country Name By IP Address using PHP

Use the following Code to get geo location details based on Your IP $country data=getLocationInfoByIp(); echo $country data['country']; echo $country data['city']; function getLocationInfoByIp() { $current_ip = @$_SERVER['HTTP_CLIENT_IP']; $forwardip = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remoteip = @$_SERVER['REMOTE_ADDR']; $geo_data = array('country'=>'', 'city'=>''); if(filter_var($current_ip, FILTER_VALIDATE_IP)) { $ipaddress = $current_ip; } elseif(filter_var($forwardip, FILTER_VALIDATE_IP)) { $ipaddress = $forwardip; } else { $ipaddress = $remoteip; } $your_ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ipaddress)); // print_r($your_ip_data); ...

Read More »

Restrict ckeditor to basic toolbar

We can use javascript or jquery to apply ckeditor configuration HTML <textarea id=”textarea” cols=”15″ name=”txtdesc” rows=”5″></textarea> Javascript Must be included ckeditor.js Take the instance of ckeditor and replace with new configuration <script type=”text/javascript”> var editor = CKEDITOR.instances[‘txtdesc‘]; if (editor) { editor.destroy(true); } var editorContent =CKEDITOR.replace(‘txtdesc‘, { toolbar: [ { name: ‘document’, items: [ ‘Source’, ‘-‘, ‘NewPage’, ‘Preview’, ‘-‘, ‘Templates’ ] ...

Read More »

Check whether url contains http or https using php

Sometimes the programmer need to identify the link contains http or https. Using php code can do this easily. First store the string to a php varible- $URLstring=”http://smarttips.in/smarttips_logo.jpg”; Second use the substr() function to find the occurrence of http or https -substr($URLstring, 0, 7) <?php $fromUrl =’0′; $URLstring=”http://smarttips.in/smarttips_logo.jpg”; if(substr($URLstring, 0, 7) == “http://”) { $fromUrl = “http”; } else if(substr($URLstring, 0, 8) ...

Read More »

Where is Seller ID in 2checkout?

website development

Login to 2checkout account using your login details 1. On the top right corner of the website header menu  can see a profile picture,please click on it 2. A dropdown menu will appear with following details. Account name Account ID Username That account ID is the seller id or sid.

Read More »

Check database exists in codeigniter

Load the Database Utility Class Notice: Databse Connection should be already established before loading the above class. <?php $this->load->dbutil(); ?> loaded class can access the functions using the  following method: <?php $this->dbutil->some_function() ?> <?php $this->dbutil->list_databases(); ?> the above function will  show an array of database names: <?php $dbs_smarttips = $this->dbutil->list_databases(); ?> <?php foreach ($dbs_smarttips as $db_name) { echo $db_name; } ?> ...

Read More »