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



function clean($value) {

// If magic quotes not turned on add slashes.
if(!get_magic_quotes_gpc())

// 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;

}

PHP CODE


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


Cleaning Variable

Tuesday 17 December 2013

HTML5 Page Structure

<!DOCTYPE HTML>

<html>

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

<body>

<header>
<nav>
<ul>
<li>Your menu</li>
</ul>
</nav>
</header>

<section>

<article>
<header>
<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>
</header>
<p>Your Content Goes Here.</p>
</article>

<article>
<header>
<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>
</header>
<p>Your Content Goes Here.</p>
</article>

</section>

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

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

</body>

</html>


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_register($session_var);


$_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?

Yes.
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”?

Yes.
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?

$formatted = ucwords(“TECHPREPARATIONS IS COLLECTION OF INTERVIEW QUESTIONS”);


print $formatted;


What will be printed is TECHPREPARATIONS IS COLLECTION OF INTERVIEW QUESTIONS.


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 “abc.com” from a string “mailto:info@abc.com?subject=Feedback” using regular expression of PHP?

$text = “mailto:info@abc.com?subject=Feedback”;


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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<img alt="ajax-progress" src="http://asp.net-informations.com/ajax/img/ajax-progress.gif"></img>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Default.aspx.cs



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)
{
System.Threading.Thread.Sleep(5000);
Label1.Text = "Server Time :  " + DateTime.Now.ToString();
}
}

Default.aspx.vb



Partial Class _Default
Inherits System.Web.UI.Page

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


ASP.NET Ajax UpdateProgress