Search Keyword:

These functions are equivalent to PHP’s trim() and nl2br() function written in Javascript and are most useful in working with formatting text inputs and textareas values.Trim() strips whitespaces from the beginning and end of a string and nl2br() inserts HTML line breaks (<br />) and replaces newlines or carriage returns(Enter key) in a string.

The function:

function trimStr(input_string)
{
return input_string.replace(/^\s+|\s+$/g, ”);
}

function nl2brStr(input_string)
{
return input_string.replace(/(\r\n|\r|\n)/g, “<br />”);
}

Usage:

You can use the functions individually or by joining them together.See the demo for sample implementations by clicking here.

This function returns a more secure password hash by using SHA1 encryption algorithm with the combination of using a salt,returning a salted hash.Salt is a random bit of data,consisting of upper and lowercase letters with the combination of numbers and special characters to be included in the string you want to hash so we can avoid the possibility of dictionary hacks.If you are using PHP 5.12 or above,you might want to look at SHA2 (sha256,sha384,sha512) encryption algorithm.

The function:

function password_hash($username,$password)
{
$salt = “123456789ThisIStheSalt9876543210″;
return sha1($username . $password . $salt );
}

In this function, I had used a 32-character,combination of upper and lowercase letters and numbers salt.You can change it to whatever random string of data you have come up with.You can also use special characters too!(!@#$,etc.).I have included the username in the parameter of the function so the string to be hashed will be more longer (username + password + salt).

Usage:

if($_POST['register_button'])
{
/* Clean first your post variables against SQL injection and cross site scripting attacks, cleaning function is not included in this tutorial */

// hash the password using the inputed username and the password
$hashed_password = password_hash($username , $password);

//proceed to inserting details in your database
}

For example, when a user register on your page, his username is “myusername” and password is “mypassword”,we will take his username and password and hash it using the function. The outcome of the hash will be “d6bbfc3af54c4736839fd339715b6698fb7d23e2″ .Isn’t that more secure than storing the plain-text password in your database?Yes it is.Then you’re ready to store the generated hash in the password field of your database.

if($_POST['login_button'])
{
/* Clean first your post variables against SQL injection and cross site scripting attacks, cleaning function is not included in this tutorial */

// hash the password using the inputed username and the password
$hashed_password = password_hash($username , $password);

//proceed to check if username and password matches in your database

}

When a user logs-in,we will take his username and password and hash it again using the same function.Then we will proceed to validate the username and the hashed password with the details stored in the database.

This .htaccess rule is to remove the index.php file in CodeIgniter URLS.There is an example on how to remove this on the CodeIgniter User Guide but unfortunately it somehow doesn’t work.Anyway, here’s how to do it:

Put this code on your .htaccess file,changing “directory_on_where_is_your_CI” in which your CodeIgniter application resides.
If your CI application is in the root, just remove “directory_on_where_is_your_CI/” .

RewriteEngine On
RewriteBase /directory_on_where_is_your_CI/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /directory_on_where_is_your_CI/index.php/$1 [L]

Put the .htaccess file on the root if your CodeIgniter application,where the system/ folder resides.To test if it is working try removing the index.php file in the URL.

example.com/index.php/news/article/my_article

can be

example.com/news/article/my_article

but produces the same output.

Sponsored Links



Recent Comments

  • admin: Thanks Tony for the share!
  • Tony Stark: Hi Admin, Thanks for the tutorial. Chicken is too slow so I Google for an alternative and I found...
  • admin: How about installing Gen-B instead of Gen-C? Here’s the download link for it:...
  • aznspryd: I hacked my PSP-3000 and installed Gen-C, but everytime i try opening a game, it restarts the psp
  • vinoth: Hi ,bro its realy workin well i.E thanks alot.