Monday, 23 December 2013

Cleaning Variable

Variables that are submitted via web forms always need to be cleaned/sanitized before use in any way, to prevent against all kinds of different malicious intent.


function clean($value) {

// If magic quotes not turned on add slashes.

// Adds the slashes.
{ $value = addslashes($value); }

// Strip any tags from the value.
$value = strip_tags($value);

// Return the value out of the function.
return $value;



$sample = "test";
$sample = clean($sample);
echo $sample;

Cleaning Variable

Tuesday, 17 December 2013

HTML5 Page Structure



<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Your Website</title>


<li>Your menu</li>


<h2>Article title</h2>
<p>Posted on <time datetime="2009-09-04T16:31:24+02:00">September 4th 2009</time> by <a href="#">Author Name</a> - <a href="#comments">6 comments</a></p>
<p>Your Content Goes Here.</p>

<h2>Article title</h2>
<p>Posted on <time datetime="2009-09-04T16:31:24+02:00">September 4th 2009</time> by <a href="#">Author Name</a> - <a href="#comments">6 comments</a></p>
<p>Your Content Goes Here.</p>


<h2>About section</h2>
<p>Aside Content Goes Here.</p>

<p>Copyright 2013 Your Company Name</p>



HTML5 Page Structure

Hides iframe until fully loaded

<iframe style="visibility: hidden;" src="yourhtmlpagepath.html" width="320"></iframe>

Hides iframe until fully loaded

Friday, 13 December 2013

Php Interview Questions and Answers

1- How can we register the variables into a session?


$_SESSION['var'] = ‘value’;
2- What is the difference between characters \023 and \x23?

The first one is octal 23, the second is hex 23.
With a heredoc syntax, do I get variable substitution inside the heredoc contents?

3- How can we submit form without a submit button?

We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form. For example: <input type=button value=”Save” onClick=”document.form.submit()”>
4- How can we create a database using PHP and mysql?

We can create MySQL database with the use of mysql_create_db($databaseName) to create a database.
5- How many ways we can retrieve the date in result set of mysql using php?

As individual objects so single record or as a set or arrays.
6- Can we use include (“abc.php”) two times in a php page “makeit.php”?

7- For printing out strings, there are echo, print and printf. Explain the differences.

echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:

<?php echo ‘Welcome ‘, ‘to’, ‘ ‘, ‘techpreparations!’; ?>

and it will output the string “Welcome to techpreparations!” print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.
8- I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP?

On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().
9- What’s the output of the ucwords function in this example?


print $formatted;


ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.
10- What’s the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars only takes care of <, >, single quote ‘, double quote ” and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.
11- How can we extract string “” from a string “” using regular expression of PHP?

$text = “”;

preg_match(‘|.*@([^?]*)|’, $text, $output);

echo $output[1];

Note that the second index of $output, $output[1], gives the match, not the first one, $output[0].
12- So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?

Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.

Php Interview Questions and Answers

Tuesday, 3 December 2013

ASP.NET Ajax UpdateProgress

UpdateProgress control shows the status information for the progress of the download occurring during the partial-page rendering in the UpdatePanel. The page can contain multiple UpdateProgress controls. Each one can be associated with a different UpdatePanel control. Alternatively, you can use one UpdateProgress control and associate it with all the UpdatePanel controls on the page. You can place UpdateProgress control either inside or outside the UpdatePanel controls. The following Asp.Net program shows how to an UpdateProgress control waits for completion of the task and during this waiting time it shows a .gif file as waiting message. Default.aspx

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<img alt="ajax-progress" src=""></img>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />


using System;
using System.Web.UI;

public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)
Label1.Text = "Server Time :  " + DateTime.Now.ToString();


Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Server Time :  " & DateTime.Now.ToString()
End Sub
End Class

ASP.NET Ajax UpdateProgress