Weblog Of Nirandas | home

Developer From INDIA

Preventing SQL injection specially for PHP developers

clock November 10, 2009 06:23 by author Nirandas

SQL injection happens when user provided input through forms or query string is directly used in a SQL query without any sanitation done to it. For example a badly coded login script would allow an attacker to login without knowing the username/password or login with full rights of admin users. Though this can happen to any web page developed in any language, this issue seems to be affected more PHP pages than .NET applications. Perhaps simplicity of PHP programming and inexperience coders are reasons for this. In any case, keeping following poins in mind while developing PHP sites should help avoid mistakes which can be prevented easily.

More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Using Smarty with codeigniter

clock February 20, 2009 07:39 by author Nirandas

If you like to use smarty for designing your views while developing codeigniter applications, just read on. Smarty is a powerful templating engine for php. Its template language is simple yet powerful. By default, codeigniter doesn't use any templating system. Instead it relies on plain old php for designing views. Integrating smarty into codeigniter is rather simple. First, download the latest smarty version and copy the libs folder into /system/application/libraries/.

Now create a new file “View.php” inside the /system/application/libraries folder. Note: the case of the filename is important it must be “View.php”. Now put the following code inside the View.php file.

More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Beginning Reflection.Emit, a basic example

clock December 25, 2008 13:49 by author Nirandas

 

The System.Reflection.Emit namespace provides us the tools required to generate .NET code on the fly. Especially the DynamicMethod class makes the job of creating small code snippet easier. In this post I’ll show a simple example of dynamically creating a method which takes a string as its argument and returns a string “hi “prepended to it. First, we will create the DynamicMethod object specifying the argument list and the return

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Determining if a Type implements an interface

clock December 22, 2008 05:08 by author

If we have an object of a type, we can easily check if that object implements a particular type by using is operator.

 

if(o is IExample)

Console.WriteLine("Yes");

 

Here the If statement will evaluate to true if the object o implements the interface IExample or the object is a derived object of IExample.

 

However, we cannot use is operator if all we got is a type and we want to find whether that type implements a particular interface.

 

Type.IsAssignableFrom()

The System.Type class has an IsAssignableFrom() method which does exactly what we want. The IsAssignableFrom() method takes a type as its argument and returns true if the object of the provided type can be assigned to a variable of the current type. See the following example:

 

interface IExample

{

 void Do();

}

class Example : IExample

{

 

    #region IExample Members

 

    public void Do()

    {

        throw new Exception("The method or operation is not implemented.");

    }

 

    #endregion

}

 

Here we are declaring an interface IExample and a class Example which implements the IExample interface. Now let us see how we can check that the type Example implements IExample interface.

 

if(typeof(IExample).IsAssignableFrom(typeof(Example)))

Console.WriteLine("Yes");

 

This will output “yes” to the console as the interface IExample is implemented by class Example class. For more information on Type.IsAssignableFrom() method, visit this MSDN page.

 

Happy coding!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Basics of PHP

clock December 21, 2008 16:56 by author Nirandas

What is PHP?

PHP is a high level scripting language particularly used in developing websites. PHP is very powerful and easy to learn. PHP is platform independent that is, PHP can run on either Linux or Windows and many other OS. Unlike C or C++, PHP is an interpreted language that is, the PHP code we write doesn’t get converted into machine code. Instead the PHP reads and executes the source code when we run the script. For more information about PHP and its history, visit http://en.wikipedia.org/wiki/PHP

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Failing tests as a reminder of unimplemented requirement

clock November 24, 2008 11:09 by author
I am a new comer to the art of unit testing and it has not yet become the part of my coding routine. However, even this early I have realized how useful writing unit tests can be. Specially writing unit tests gives you the understanding how the class will be used and where the errors can arise etc. For example passing the Type System.String to a method where the method expects a Type which implements a particular interface ICommand should result in an error because the System.String does not certainly implements the interface ICommand. But does the method validate the input?Now writing a test for this case is very simple. Just create the object, call the method with System.String as the Type parameter. [Test][ExpectedException(typeof(ArgumentException))]public void CanNotRegisterTypesNotImplementingICommand(){CommandLocater locater=new CommandLocater();locater.RegisterCommand(1,typeof(string));}Certainly I haven’t implemented the validation code for checking this, so the test is certainly failing. Until I feel like doing this validation, this test will always fail. Lot better than forgetting to write this code and getting an unrelated exception in any other section of the code is getting a failing test which will make sure that I’ll write the code necessary to implement this requirement.“Always write tests to break your code.”
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Who Am I?

I am Nirandas - a developer from INDIA

Sign in