Page 1 of 1

Logging in, & sessions o_O

Posted: Mon Dec 04, 2006 3:52 pm
by Mythic Fr0st
Q1: logging in

now, everything works pretty well, but I need to know a few things

how do I redirect to a new page with no event?

IE your at login page, your details are correct, and it instantly redirects you (on page loading) to "home" page

Q2: sessions, I get what they do, but i've been told to use them for logging in and stuff, but why? whats the point? what kind of things can you do with em other then counting pages lolz

Authentication

Posted: Mon Dec 04, 2006 4:03 pm
by timclaason
For redirecting, you can use

Code: Select all

Header("Location: pagename.php?anydesired=querystring");
For sessions, you can use sessions for anything you would use a cookie for. Session settings, storing username on client side, etc. It's basically anything you want to keep on the client side.
One thing I use sessions for is to generate session ids.
PHP code is

Code: Select all

session_id();
session_id() generates a hexadecimal string that is unique. I can then stick that string into a database, and compare the database value to the client side value. I can check to see how long they've been logged in, or if they've logged in before. The sky is the limit, really.

Plus, I'm sure someone will post a good link to a page outlining how to uses $_SESSION[]

Posted: Mon Dec 04, 2006 4:28 pm
by hrubos
if you can need, I can post my code about login by session and md5

ok

Posted: Mon Dec 04, 2006 4:42 pm
by Mythic Fr0st
that'd be good thanks ^_^

also getting a header error

Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\mythic aeons\action=login.php:4) in

hmm?


Code: Select all

if ( false!== $userdata) 
{
sleep(5);
Header("Location: Home.php"); 
}
else 
{
echo "your not registered";
}

Error

Posted: Mon Dec 04, 2006 4:53 pm
by timclaason
For header to work, output_buffering needs to be on in php.ini. Or you can do ob_start() in your code, just before the Header.
PHP freaks if there's already been page output before the Header("Location:..."). So, it's best to not output any HTML, etc on your page prior to doing the redirect.

Re: Error

Posted: Mon Dec 04, 2006 5:17 pm
by feyd
timclaason wrote:For header to work, output_buffering needs to be on in php.ini. Or you can do ob_start() in your code, just before the Header.
PHP freaks if there's already been page output before the Header("Location:..."). So, it's best to not output any HTML, etc on your page prior to doing the redirect.
output buffering is a band-aid approach to the problem, it's not a solution.

viewtopic.php?t=1157

...

Posted: Mon Dec 04, 2006 5:26 pm
by Mythic Fr0st
Erm, that makes it harder to see how I could do anything -.-

like, how could I possibly

check if the username & password doesnt match,

"Display error"

if it does match

(redirect to Home.php)

it doesnt make sense:/

Posted: Mon Dec 04, 2006 6:36 pm
by RobertGonzalez
Might I suggest you search the forums/google/PHP.net for information regarding what you want to do. A lot of what you are asking are commonly asked, new-to-PHP type questions that I am sure have been answered before. Try some stuff, post some code, search for answers. Before asking the question, please.