Monthly Archives: February 2010
Private Constuctors in C# (Csharp)
Private constructor are very important feature used extensively in Object oriented design and development. They are used when you don’t want to instantiate class and at the same time use its members. They are used when class only has static … Continue reading
Themes in ASP.Net
A theme is a collection of settings that define the look of controls and web pages. Themes are applied across all the pages in a Web application to maintain a consistent appearance. A theme is a file with .skin extension … Continue reading
Application Error Tracing in Asp.Net
Tracing is the concept or process of locating errors in code/codes. It is a new feature of ASP.NET.The previous versions of ASP does not supports tracing.It was inevitable to write a few Responses.Write commands in web pages just to see … Continue reading
Web Configuration files in asp.net
There is an advantage in ASP.NET of grouping individual pages together into an application is that we can set values to all these pages at one shot.That is by setting the properties of the application.The setting of values for the … Continue reading
Differences between class and structure c#
Following are the differences between structure and classes 1. Structures are value type and Classes are reference type. 2. Structures can not have constructor or destructor. Classes can have both constructor and destructor. 3. Structures do not support Inheritance, while … Continue reading
SQL CASE Expression
SQL CASE evaluates a list of conditions and returns one of multiple possible result expressions. It helps to provide multiple if conditions type of logic in our SQL Query. Lets look in to an example : Consider a Table Orders … Continue reading
Generate HTML table with alternating row styles
The following code shows you how to display a table of information with alternating rows having different visual appearance. The even-numbered rows in a table have a white background and odd-numbered rows have a gray background. <style type="text/css"> .even-row { … Continue reading
Read complete POST data in PHP
If a developer wants to read the complete body of a post request and not just the parsed data that PHP puts in the super global array $_POST, we can use the php://input stream. This can be used to to … Continue reading
Browser capability object properties
Most capabilities of get_browser() function are shown below. For user-configurable capabilities such as javascript or cookies, though, get_browser() just tells you if the browser can support those functions. It doesn’t tell you if the user has disabled the functions. If … Continue reading
Get browser capabilities information
The object returned by get_browser() can be used to determine a browser’s capabilities.The get_browser() function examines the environment variable (set by the web server) and compares it to browsers listed in an external browser capability file. We can download php_browscap.ini … Continue reading
Not following redirects in PHP
PHP’s http stream wrapper automatically follows redirects. Since PHP 5.0.0, file_get_contents( ) and fopen( ) support a stream context argument that allows for specifying options about how the stream is retrieved. In PHP 5.1.0 and later, one of those options … Continue reading
Retrieving a protected page with HTTP_Request
<?php $r = new HTTP_Request(’http://www.w3mentor.com/protect.php’); $r->setBasicAuth(’username’,'password’); $r->sendRequest(); $page = $r->getResponseBody();
Retrieving a password protected page with cURL
<?php $c = curl_init(’http://www.w3mentor.com/protect.php’); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLOPT_USERPWD, ‘david:hax0r’); $page = curl_exec($c); curl_close($c); ?>
Retrieving a password protected page using PHP
<?php $url = ‘http://username:password@www.w3mentor.com/protected.php’; $page = file_get_contents($url); ?>
Building a query string with http_build_query()
To retrieve a page that includes query string variables, use http_build_query( ) to create the query string. It accepts an array of key/value pairs and returns a single string with everything properly escaped. You’re still responsible for the ? in … Continue reading
Fetching a remote XML document in PHP
<?php $url = ‘http://rss.news.yahoo.com/rss/omg’; $rss = simplexml_load_file($url); print ‘<ul>’; foreach ($rss->channel->item as $item) { print ‘<li><a href="’ . htmlentities($item->link) . ‘">’ . htmlentities($item->title) . ‘</a></li>’; } print ‘</ul>’; ?>
Fetching a URL with HTTP_Request
<?php require_once ‘HTTP/Request.php’; $r = new HTTP_Request(’http://www.w3mentor.com/robots.txt’); $r->sendRequest(); $page = $r->getResponseBody(); ?>
Fetching a URL with cURL
cURL is a very useful PHP library which can be used to connect to different types of servers with different types of protocols. Here is a very basic example of its primary usage to fetch a page. <?php $c = … Continue reading
Fetching a URL with file_get_contents()
To retrieve the contents of a URL. For example, you want to include part of one web page in another page’s content, we can use the file_get_contents() function in php. <?php $page = file_get_contents(’http://www.w3mentor.com/robots.txt’); ?>
Get name of current controller and action in MVC
Use this.RouteData.Values(“action”) and this.RouteData.Values(“controller”) for getting name of current controller and action in MVC instead of going through the ValueProvider. The RouteData contains information on the request / route (including controller and action), and the value provider contains information used … Continue reading