PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Well I've been thinking for a while and still cannot come up with a good way to display my login/session errors.
Example: User tries to access a secure page without being logged in. I want to send him to the login page but I also want text above the login to say something like "You cannot access that page until you are logged in".
THe only way I can think of is by passing it in the URL (login.php?error=Please%20Login . . .) but I'd rather not have the error message displayed in the address bar. Does anyone have an idea of how to do this another way?
<?php
echo "<TABLE border='0' cellpadding = '1' cellspacing = '1' bgcolor = '#cccccc'>"
echo "<TR><TD colspan='2'>";
$str_warn = $_GET['warn'];
if $str_warn==1
{
echo "Invalid login. Please check your user name and password and try again.";
}
echo "</TD></TR>";
echo "<TR><TD><INPUT type = 'text'........
?>
and so on.
In my actual code, I have an array of warning messages stored in a table, and I use that, or a switch statement on str_warn, to draw the appropriate message, or none at all.
I've found that over the last few months I've been using $sessions more and more to store site data.. especially navigation and user/member info etc... it makes the info nice an easy to grab and it also keeps the address bar a bit more tidy.
I don't know how you use $sessions but I tend to create a single variable for say the member information as an object, a bit like...
I don't know to be honest, can't say that I've noticed any slowdown at all though.
A new site I'm working on loads the entire members profile and site settings into a single session object (like above) which is about 35 different variables from single numbers (int) through to the members biography which can be a big chunk of text (mysql longtext).
I guess it's quicker than constantly loading the info from a database, and once it's loaded you don't need to load it again.... unless the member changes their profile in which case you save the changes to the database and then reload the members info into the session.
And for myself it's also an ease-of-use and keeping-things-tidy way of working. Give it a whirl to try it out.. if you like it do it, if not don't