Learnwebdevelopment
497 views | +0 today
Follow
Learnwebdevelopment
You can learn web development things and web programming things like HTML, PHP, MySQL, Javascript, Ajax, jQuery etc.
Curated by Iam Raj
Your new post is loading...
Your new post is loading...
Scooped by Iam Raj
Scoop.it!

How to change php date format? | Learn Web Development

How to change php date format? | Learn Web Development | Learnwebdevelopment | Scoop.it
Most of country using different date format for filling the form and day activity. So the PHP provide many date formats. See list of Date Format Here, we
more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

How to make case sensitive password in php

How to make case sensitive password in php | Learnwebdevelopment | Scoop.it
The user can login with case-insensitive way Means if your password is 'test' then user able to login with 'TEST' password. So  to avoid the such type authentication on password field and make strong authentication.
more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Store and retrieve passwords with PHP | Tutorial | Learnwebdevelopment.info | Learn Web Development

Store and retrieve passwords with PHP | Tutorial | Learnwebdevelopment.info | Learn Web Development | Learnwebdevelopment | Scoop.it
Sample PHP code for Store and verify the encrypted passwordHere use Base64-encoded and decode function to store and retrieve the password.The Base64-encoded function work processPassword change into random letters, numbers and/or characters.Base64-encoded data takes about 33% more space than the original data.
more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Resolved the timed out error while using HttpWebRequest

I tried to use HttpWebRequest object for getting response code from webpage. 
system.net.webexception the operation has timed out

After doing google search I came to know that we can't use more than one connection for getting response from pages of same server.

So closing the connection using "Close()" after getting the response has resolved this issue.

And also, I came to know that just for finding whether a page exists, we need not get the all the response string. Using HttpWebRequest.method="HEAD" will get only the header part. This will improve the execution speed.
More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Removing white spaces entered in TextArea tag of HTML page

White spaces entered inTextarea of HTML page will be considered as Characters even when no other characters are entered.

These white spaces will then be inserted into database table unnecessarily.

So, to avoid this issue the below Javascript code can be used. 

It will clear the whitespaces in the Textarea.



var str=document.getElementById(“category_name”).value;
var pattern_white_space=/^\s{1,4}/g;
var pattern_any_characters=/\w+/g;

if(str.match(pattern_white_space)&&!str.match(pattern_any_characters))
{
document.getElementById(“category_name”).value="";
}



More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Javascript code for preventing user from copying content from webpage

Find below the javascript code for disabling Mouse right click in web browser to prevent user from copying the content.

Buy anyway the content can be copied from many other ways such as from view source.

This code won't help if the user disables the javascript in his browser.

I am just curious to know whether any code/way available to prevent webpage content copying completely.





<script language='JavaScript1.2'>
function disableselect(e){

return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>


More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

PHP code for preventing session hijacking

The hacker may get session id of our browser in someway, and then using this session id they can continue our session in their browser.

So this session hijacking will allow the hacker to use our login restricted web pages without knowing our login credential.

Say for example, the hacker can read your emails from their browser itself if they just know session id of your browser.

Find below the sample code written in PHP for preventing session hijacking.



function prevent_session_hijacking()
{
//code for preventing session hijacking
session_start();

//Regenerate SessionID for avoiding Sesssion Fixation

if (!isset($_SESSION['initiated']))

{
session_regenerate_id();
$_SESSION['initiated'] = true;

}

//for preventing session hijacking.
if (isset($_SESSION['HTTP_USER_AGENT']))

{
if ($_SESSION['HTTP_USER_AGENT'] != md5($_SERVER['HTTP_USER_AGENT']))

{
exit;

}

}

else

{
$_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
}

}



We have to do many other Security testing (e.g sql injection, Cross-site scripting) to make sure your website is safe for your users.
More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Doing page redirection in PHP

Page redirection can be done in PHP file usingheader() which is used to send a raw HTTP header.

(i-e) header("Location:newpage.php"); will load the newpage.php.

Note that header() must be used before sending any output either by HTML tags, blank lines or from PHP. Otherwise error message "header already sent" will be shown.

In this situation, we can use javascript for doing page redirection as below

window.location="newpage.php";

Some users might have disabled javascript in this browser for security reasons.
In this case, we can show a link for them go to the desired page.

Find below function written in PHP for doing page redirection by handling all the scenarios.


function redirect()
{

if (!headers_sent()) header("Location:newpage.php");
else echo "<script>window.location=\"newpage.php\";</script>
<noscript>Automatic redirection didn't work.<br />
<a href=\"newpage.php\">Click here to go to newpage.</a></noscript>";
}




If you want to use the variables of current page in the new page also, then include the new page (e.g include "newpage.php";)instead of doing redirection.

More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

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 javascript function ValidateForm



<form name="frmSample" method="post" action="" onSubmit="return ValidateForm();">
<p>Enter an Email Address :
<input type="text" name="txtEmail">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>



The javascript function ValidateForm is calling another function emailcheck to validate syntax of the email id.


<script language = "Javascript">

function emailcheck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){

return false //if @ symbol is not there
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

return false //if @ symbol available at starting or ending of email.
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

return false //if "." is not available, or available at beginning or end of email.
}

if (str.indexOf(at,(lat+1))!=-1){

return false //if more one @ symbol available in email
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

return false //if no letter is available between @ and "."
}

if (str.indexOf(dot,(lat+2))==-1){

return false
}

if (str.indexOf(" ")!=-1){

return false //if blank space available in email.
}

return true
}

function ValidateForm(){
var emailID=document.frmSample.txtEmail

if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID")
emailID.focus()
return false
}
if (emailcheck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return true
}
</script>


More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

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.

php is having a function rand() for getting random number within a range. Syntax is shown below.

int rand ( int $min , int $max )

Sample code is shown below.


$sqlbanner="select * from table_name
$recbanner=mysql_query($sqlbanner);
$rows=mysql_num_rows($recbanner);
$rand=rand(0,$rows-1);
$page_text=mysql_result($recbanner,$rand,'page_text');



We can use RAND() function of MySQL also to achieve this.

For example below code will select 10 random rows from the mysql table.

SELECT * FROM <table name> where <condition> ORDER BY RAND() LIMIT 10
More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Deleting Session Cookie in Webbrowser control

We know that many websites are using cookies for storing some user data in browser to improve user
experience. C#.net is having webbrowser control for creating applications useful for automatically navigating/crawling websit.

more @ http://www.qualitypoint.blogspot.com/2009/07/deleting-session-cookie-in-webbrowser.html

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

The Reason why Facebook is NOT providing "Dislike" button

The Reason why Facebook is NOT providing "Dislike" button | Learnwebdevelopment | Scoop.it

Many Facebook users are expecting to have "Dislike"button so that they can use this "Dislike" button if they don't like any particular content posted in Facebook. More than 3 Millions "Likes" for the Dislike button facebook page shows how people are very eager to get "Dislike" button in Facebook.

Anyway, Facebook is already having many options to report/hide the story/links which you don't like. But the Facebook users are willing to have exact "Dislike" button. I too had the question why Facebook is not providing "Dislike" button.

But recently I realized the reason why Facebook is NOT providing the "Dislike" button. It seems providing "Dislike" button will create mess-ups.

 

Let me explain it completely.


Last week, I had uploaded this video about the Marriage of Facebook's Mark Zuckerberg with Pricilla Chan.

Immediately after uploading this video, many people clicked the "Dislike" button. Right now this video is having more "Dislikes" than the number of "Likes".

Initially I couldn't understand why this video is getting more "Dislike". So, I asked about the reason for these "Dislikes" thro' the Comments.

And, I got the answer from the replies for my comments. i-e Many people clicked the "Dislike" button in the YouTube video as they didn't like the marriage of Mark Zuckerberg with Pricilla Chan because of racism.

 

To More @ http://www.qualitypoint.blogspot.in/2012/05/reason-why-facebook-is-not-providing.html

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Implementing Google Suggest in Search box using jQuery AutoComplete plug-in

Implementing Google Suggest in Search box using jQuery AutoComplete plug-in | Learnwebdevelopment | Scoop.it

One of our Customers wants to have Auto Suggestion similar to Google search in the Search input of his website.


So, I referred this article for implementing this Google suggestion using jQuery AutoComplete plug-in.

I came to know that we can use http://suggestqueries.google.com/complete/search?qu=qualitypoint&nbsp;for getting auto Suggestion from Google. But I am not sure whether it is officially supported by Google as API. Anyway it is working fine.


But I couldn't directly use the output of this suggestion in AutoComplete plug-in.

The reason is, search querystring "q" is hard-coded in the jQuery AutoComplete, but the Google suggest is using "qu" as search query string parameter.

So, I wanted to use a separate php file as proxy or bridge between them.

The code looked something similar to below one.



<html>
<head>

<title>jQuery Autocomplete Plugin</title>
<script type="text/javascript" src="../lib/jquery.js"></script>
<script type='text/javascript' src='../jquery.autocomplete.js'></script>
<script type='text/javascript' src='localdata.js'></script>
<link rel="stylesheet" type="text/css" href="main.css" />
<link rel="stylesheet" type="text/css" href="../jquery.autocomplete.css" />

<script type="text/javascript">
var keywords=['qualitypoint','qpt','quality','one','two'];
$().ready(function() {


$("#q").autocomplete("search.php", {
width: 260,
selectFirst: false
});

$("#q").result(function(event, data, formatted) {
if (data)
$(this).parent().next().find("input").val(data[1]);
});


});

</script>
</head>

<body>
<div id="content">
<form autocomplete="off" >
<p>

<input type="text" id="q" />

</p>
</form>

</div>
</body>
</html>





Here the search.php is the bridge/proxy page.

Find below the content of this page.

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

How to store array value in database using php?

How to store array value in database using php? | Learnwebdevelopment | Scoop.it

Here we discuss about how to update the array value in the database.

Let discuss the sample code

Here the user update the studied information in the database

   if(empty($_POST['col_name']))           //check the condition for array of data empty {echo "There's nothing in the array.....";}else{foreach($_POST['col_name'] as $key=>$name)   //Using foreach loop to retrieve and store the data{$query=mysql_query("update education set college_name='$name',college_address='".$_POST['col_add'][$key]."',course_study='".$_POST['col_study'][$key]."',where employee_id=$employee_id);}}

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

PHP Code For Custom Login

PHP Code For Custom Login | Learnwebdevelopment | Scoop.it

Why we want to use custom login?, Because we must separate from user and admin account and we must be disabled some feature in user account. And similarly, activate all feature in admin account.

PRIVILEGE ADMINISTRATION Privilege Administration refers to the ability to change privileges. This is the most dangerous of all privileges! If you grant someone the privilege of Privilege administration, then not only will they be able to edit their own privileges, but they’ll also be able to edit the privileges of any other person you may have granted account access to.

Essentially, someone with the privilege of Privilege Administration has the same power over an account that the account owner does. So We must be give some conditions for login time.

In the picture below you will see the difference from what you can see in your account and what the Privileged user account you just setup can see when they login.

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Free Markup validation service provided by W3C

W3C is providing free Markup validation service. Using this service we can validate XHTML/HTML syntax of webpages just by giving the URL of the website.
And also, we can validate the syntax by uploading the file or just by pasting the code.

URL of this service is http://validator.w3.org/

W3C is providing free service for checking broken links online and for checking CSS style syntax also. 

You can refer this link for seeing complete list of validators provided by W3C.
More Articles...

 
more...
GA13's curator insight, March 20, 2014 2:07 AM

Important resource for later.

Scooped by Iam Raj
Scoop.it!

PHP code for listing files in a Folder

Below PHP code will be used for listing files in a folder.



<?php
$folder=dir(".");

while($folderEntry=$folder->read()){
echo $folderEntry."<br>";
}

$folder->close();

?>



More Articles...

  
more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

SQL query for deleting duplicate records in parent table without affecting child table

We need to take additional care when deleting duplicate rows in a table if the table is related with another table and there are no proper foreign key constraints available.

Consider below two tables. The parent table is having duplicate rows. If we just blindly delete the duplicate rows in the parent table, the child table rows associated with the duplicate parent row will be in trouble.
So to avoid this issue we need to update the child rows with available parent row ids once after removing duplicate rows in the parent table. Anyway the best way is defining appropriate foreign key constraints.

Find below the DELETE query for deleting duplicate rows in the parent table and UPDATE query for making necessary changes in child table once after executing the DELETE query.



Delete
from parent_table
where id not in
(select min(id) from parent_table P2 where P2.Name=parent_table.Name)

update parent_table p,child_table c set c.parent_id=p.id
where c.parent_id not in
(select c.parent_id from child_table c, parent_table p where c.parent_id=p.id)
More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Dynamically changing/displaying web page content using javascript without refreshing the page

Sometimes we may need to change the content displayed in the webpage frequently.
Javascript will enable achieving this without the need for refreshing the webpage.(i-e without requesting the page again).

Below steps are needed for doing this.
- All the contents should be stored in a Javascript array.
- Body onLoad event will call a function thro' a javascript method setInterval().
- setInterval() method will behave similar to setTiemout() which will call a function after preset time. Additionally setInterval() will call the function repeatedly.

You can refer the below code. This blog is using the similar code for displaying Quotes in side bar.


<html>
<head>
<script type="text/javascript">
var quoteIntervalId = 0;
var arrQuotes=[
'quote1',
'quote2',
'quote3',
'quote4'];
function displayQuote ( )
{
quoteIntervalId = setInterval ( "showQuote()", 1000 );
}

function showQuote ( )
{
var randnumber=Math.random ( )*1000;
randnumber=parseInt(randnumber);
var count_quotes=arrQuotes.length;
var quoteindex=randnumber%count_quotes;
document.getElementById("quotemsg").innerHTML = arrQuotes[quoteindex];
}

</script>
</head>
<body onLoad="displayQuote();">
<div id="quotemsg"></div>
</body>

</html>



Here,
- arrQuotes is a javascript array used for storing all the content when requesting the page.
-Call displayQuote() function from onLoad event of body tag.

- The displayQuote()function uses setInterval() to call another function showQuote after 1000 milli seconds (1 second) repeatedly.

- The showQuote() function uses Math.random() to generate a random number, and used modulo operator(%) to normalize/limit the random number within the number of items in the arrQuotes array.

- Take the content from the array based on this normalized random number and InnterHTML of a div tag ( with id quotemsg) is set with this content.
More Articles...

 
more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Workaround for Back button issue in FCKeditor.

FCKeditor is very useful tool for allowing the user to enter the formatted text in a webpage without having knowledge in HTML.

If we click Back button in the browser once after entering content using FCKeditor, the browser won't go to actual previous page, instead it will remain in samepage with the empty content. We noticed that clicking Back button two times displays correct previous page.

To avoid this issue, we have used below workaround.

- We provided a separate back button in the webpage. In the onclick event of this button, we called a javascript method to simulate clicking of browser back button two times.

- Find below the sample code.

<button onclick="javascript:history.go(-2);">Back</button>

And also, we have noticed that sometimes (e.g. after saving the content) we need to click browser back button 4 times to go the previous page.

To handle this scenario, we can enhance the above sample code by replacing -2 with a PHP variable whose value should be set either -2 or -4.

for example,

- pass a querystring parameter confim=updated once after finishing the save operation.

- use below code to assign value for a php variable based on the flow.

if (isset($_GET['confirm']))
{
$backcount=-4;
}
else
{
$backcount=-2;
}


- Now this php variable can be used in our previous sample code.

<button onclick="javascript:history.go(<?php echo $backcount;?>);"> Back</button>

updates on May 08:

It seems we need to use "return false" as below to avoid issue in some browsers (IE 7 and FireFox).

<button onclick="javascript:history.go(<?php echo $backcount;?>);return false;" > Back</button>

More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

MySQL - Resolved null issue in query.

We have faced strange issue with MySql old version (version 4).

Our php file will pass a querystring variable "id". It can have a value or it can be empty in some situation.

Initially, we used below code,
$id=$_GET['id'];

$sql="select school_name from school_table where id=$id";
$result=mysql_query($sql);

It was working fine if the $id is assinged with a value.
It showed syntax error if $id is not having any value.

Below workaround resolved the issue.

Added below code above the query.
if ($id=="")
{
$id="null";
}
More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Javascript validation for radio button in HTML form

HTML is having INPUT tag with radio as type to display radio button in the HTML form.

Multiple input tags should be given same name to make it one group.

Consider below code which will allow the user to select any one of 3 topics.


<form>
<input type="radio" name="topicname"/>topic1

<input type="radio" name="topicname"/>topic2

<input type="radio" name="topicname"/>topic3
</form>



If you want to keep this radio value selection as mandatory (i-e topic should be selected before submitting the form), you can use below javascript function.


function validation(myform)
{
var myOption = -1;
for (i=myform.topicname.length-1; i > -1; i--)
{
if (myform.topicname[i].checked)
{
myOption = i;
i = -1;
}
}
if (myOption == -1)
{
alert("You must select a Topic");
return false;
}
}



More Articles...

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Does "Safe Mode" of PHP really give any benefit?

Iam Raj's insight:

We had used ImageMagick tool for resizing the images without affecting quality in our BookMarklet project.
We implemented this project successfully in Client's server. After few Months, client informed me that this tool is not working when
they moved the code to another server.

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Handling Date and Time in PHP/MySQL |

Handling Date and Time in PHP/MySQL | | Learnwebdevelopment | Scoop.it

Date and time can be inserted into mysql table in specific format only. But php will support different types of date and time formats.

So, we should convert the date and time from php into specific format before inserting the value into mysql table.

We can use the date() and strtotime() functions of the php to do it.

MySQL table will store and datetime correctly only when it is formatted as Y-m-d H:i:s.

(i-e) 4 digit year-2 digit month - 2 digit day blankspace 24hours hour:minute:seconds.

Refer the below sample code used for inserting datetime into mysql table.

- Assume that Date and time values are stored in two different variables($dateinput,$timeinput) in php.
- First we need to concatenate both date and time to get single string.
- Then use strtotime() to convert this single string into time data which can be formatted using date() function to get required format. 

To more @ http://www.qualitypoint.blogspot.in/2009/04/handling-date-and-time-in-phpmysql.html

more...
No comment yet.
Scooped by Iam Raj
Scoop.it!

Google Map API - A Powerful and Free way to add value for your web applications

Google Map API - A Powerful and Free way to add value for your web applications | Learnwebdevelopment | Scoop.it

Google Maps is getting more popular as it is helping people to know the places and to get directions easily. Google is adding lot of information and satellite images of many places in the world to make the Google Map more useful.

And, it helps them to get directions from mobile phone also.

Google is taking steps to promote Google places ( formerly Local business center) which lists verified business addresses with more details (e.g business hours, phone number, website).

Almost all websites are now showing their office locations/addresses using Google Map.

Google Maps provides a highly responsive, intuitive mapping interface with embedded, detailed street and aerial imagery data.

Map controls can be embedded to give users full control over map navigation and the display of street and imagery data.

And, Google allows the Users to freely use Google Maps in their services.

i-e A Real Estate website can integrate Google Map in their real estate search results. The result location can be displayed in the Google Map so that the users can understand more about the search results.

Lot of similar services are developed using Google Map. You can refer this blog to know various applications/services that are developed using Google Map API Google is providing this API freely in different formats such Javascript, Flash, Static Maps and webservices.

For using this Google Map API, we need to get API key from Google. You can get API key from here.

more...
No comment yet.