Blog Archives

Setting UserAgent for php curl session to avoid 500 Internal Server Error

We are using below function for getting webpage content using curl module of php. function getmethod_request($ch,$ckfile,$urlValue) { curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //The name of the file containing the cookie data. The cookie file can be in Netscape format, or just plain

Posted in Php Tagged with: ,

Removing Last Character in a String

In PHP, we will be requiring to remove the last Character from a string variable. For example, consider below query. select * from employees where employee_id in (1,2,5,7) Assume that the employee_id values 1,2,5,7 should be dynamically collected from a

Posted in MySQL, Php Tagged with: ,

Javascript code for changing list box (select tag) value based on change in another listbox

Javascript can be effectively used for dynamically changing value in one drop down list (i-e select/option tag) when a value in another related drop-down list is changed. Assume that a webpage is having list of names in one drop-down list

Posted in Javascript Tagged with: ,

Email syntax validation using javascript

We should validate the syntax of email entered in the form in the client side itself to save unnecessary server process to validate the email. It can be done using javascript. Consider below form. onSubmit event of Form is calling a

Posted in Javascript Tagged with: ,

PHP function to get the ID generated from the previous INSERT operation in mysql

It is necessary to get the ID (auto increment field) of a row inserted into a mysql table if the table is having any parent-child relationship with one or more child tables. For example, assume that we are entering questions

Posted in MySQL, Php Tagged with: ,

Displaying Random records from MySQL database table

Sometimes we may need to display some value selected from database table which is having many records. In this situation we can select them randomly to improve user experience. It applies to displaying random advertisements, testimonials, quotes,images,background colors and news.

Posted in MySQL, Php Tagged with: ,

Displaying vertical scroll bar dynamically in HTML elements

Vertical scroll bar in HTML controls/elements/tags such as TEXTAREA and SELECT will be useful if the element has more content/items. But always showing Vertical scroll bar will be occupying some space in the page unnecessarily. So the best way is,

Posted in Html Tagged with: ,

Allowing Users to Change attribute of the HTML tag using javascript

Normally we will set values for attributes of HTML tag during design time. But each user will be expecting different values. For example “scrollamount=’2′” set in marquee tag may not be suitable for all users. Some people will expect more

Posted in Html, Javascript Tagged with: ,

How to get last row from database table

If you want to find last row in a table in your database there is no need to loop through to get the last record .Mysql provides you with a provision for that . It is easy to find last

Posted in MySQL Tagged with: ,

PHP code for preventing session hijacking

Session security is a sophisticated topic, and it’s no surprise that sessions are a frequent target of attack. Most session attacks involve impersonation, where the attacker attempts to gain access to another user’s session by posing as that user. The

Posted in Php Tagged with: ,