Logging in, & sessions o_O

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!

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

Logging in, & sessions o_O

Post 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
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Authentication

Post 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[]
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post by hrubos »

if you can need, I can post my code about login by session and md5
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

ok

Post 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";
}
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Error

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: Error

Post 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
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

...

Post 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:/
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply