Life, SAP, Consulting, Programming, Coding, ASP.NET, Sharepoint, MVC, Javascript, PHP, WebDesign, CSS, HTML

Hello there,
This is new to me and I don’t want to miss it. Redirect function in web programming is very common used. However, until recent time I didn’t know how to use it correctly. Today I will explain here why it make me write this blog entry.
For example, you are using PHP and write a redirect instruction send to user browser. And you are checking for an user login. The logic in your mind is if the check returns false, then user will be redirect to a different page. If true, is return, authenticate user.

//if invalid user + password => redirect

if( !$validUser)  {

header(“Location: http://yoursite.com/login-failed”);

}

$session[‘user’] = “authenticated user”;

Without exit function after redirect function, the user will be automatically authenticated next visit.

If you are working with CakePHP, the correct way to call redirect in Controller is

$your_controller->redirect($url, $status = null, $exit = true) ;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: