I recently learned how to make a registration form and a login form, and I've done my first work with sessions. Yet I'm getting more confused every day.
Let's start with my login page at mysite/admin/login/index.php. The following code is near the top of the page:
<?php session_start(); ?>
A form on the page sends the person logging in to login-submit.php. The same session code is near the top of that page:
<?php session_start(); ?>
I also have a database-driven quiz at mysite/test/gw-intro1
. After you select all the questions and click the Submit button, you're forwarded to mysite/test/grade.php
, where you can see your score. If you're logged in, your username and score should also be inserted in the database.
But how are the pages in the test section (mysite/test
) supposed to know I logged in at a different section (mysite/admin
)? Do I need to put session_start()
at the top of every page on my site?
In fact, my test page did somehow "know" if a user was logged in, though I haven't been able to get the username into the database, just the test scores. But something went wrong, and the test doesn't know when I'm logged in now.
My session_start()
code also triggers endless error messages, though I'd better save that for another post. Right now, I'd just like to know how to make the pages at mysite/test/gw-intro-1
and mysite/grade.php
"aware" that the person selecting answers is logged in.