then it works fine. If no session or cookie is set then the user is redirected. I don't want to do it this way because I don't actually want to do anything if the user is logged in, I only want to worry about if the cookie or session isn't set so I can redirect them. I tried to reverse the logic like this:

Not sure whether this is the problem or not, but isset() may be too sensitive a test. You might want to use empty() instead. A field can be TRUE for isset() but FALSE for empty(), according to the man pages.

Sorry, I did type isset but I noticed when typing it now that spell check changed it to asset, haha!

Thanks, Ray. I have been reading that from your previous post on my last question.

I think this is your code which is doing a similar thing:

function access_control($test=FALSE){ // REMEMBER HOW WE GOT HERE $_SESSION["entry_uri"] = $_SERVER["REQUEST_URI"]; // IF THE UID IS SET, WE ARE LOGGED IN if (isset($_SESSION["uid"])) return $_SESSION["uid"]; // IF WE ARE NOT LOGGED IN - RESPOND TO THE TEST REQUEST if ($test) return FALSE; // IF THIS IS NOT A TEST, REDIRECT TO CALL FOR A LOGIN header("Location: RAY_EE_login.php"); exit;}

This is saying that if either the session or cookie is empty(), return TRUE. In other words, a session alone is not going to allow the client to be logged in; there must be a separate cookie, too. That's probably not what you want.

Would you only use this as an extra security layer with a session based login because then you will always have to come from the login page to get to your account area? But it would not work with cookies because I might just open my browser and go directly to the account page and completely bypass the login page?

$_SERVER["REQUEST_URI"] is the page you are currently on. If you want to see where you came from, use $_SERVER["HTTP_REFERER"]. $_SERVER["HTTP_REFERER"] is Not set if you went directly to the page instead of from another page. And since it can be spoofed, you should not rely only on it. I do use it on a lot of pages though. If they can't get that right, they shouldn't be there anyway.

This is a complicated issue that produces a simple, intuitive, "good-UX" result. If you read the article and still have questions about why we use that, please post a new question and I'll try to explain.

Thanks guys. Ray, I have read the part of the article which explains it and I have looked at the code but I still can't understand why exactly you do it. I initially thought that maybe it was for if you are browsing a site and for example find a page with a particular product or article and you want to make a purchase, then if you login you will stay on that page instead of being taken to your dashboard and you have to hunt for that page again. But that probably isn't it. I will open a related question.

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.

Originally, this post was published on Monitis Blog, you can check it
here
.
In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…

Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…