Passing a URL variable through login page into session variable
Copy link to clipboard
Copied
I have a dynamic list of events and event ids (page 1). When a person selects an item from the list, they are taken to a sign-in page and the event name and id are passed via URL variables. Once the login is confirmed, i want to continue using the event name and id on the pages that follow. What is the best way to do this? I can't seem to get anything to pass through the login page to the page that follows.

Copy link to clipboard
Copied
For many of us that are not mind readers on this forum it might help if you mention what server side scripting language you're using.
best,
Shocker
Copy link to clipboard
Copied
I am such a beginner at this, that I am not sure I can answer that. My site was built in Dreamweaver with php and mySQL (MAMP for testing).

Copy link to clipboard
Copied
php is your server side language then. Please clarify the rest of your scenario with specifics. When someone clicks an event what is the parameters being passed? Ideally you'd have URL parameter keys consistent and have the value change depending on the event selected. So if someone clicks on event #1 in LA the url on login is something like this:
login.php?location=la&id=1
and if someone clicks on event #7 in New York the url on login is something like this:
login.php?location=ny&id=7
Is this how you currently have it setup or are the URL params different each time like this:
login.php?ny=7 or login.php?la=1
Please advise on how your URL parameters are being sent to login page. Also, do you want session set upon sucessful login or is it ok to set session variables before login and then use the values of those session after login is sucessfull.
best,
Shocker
Copy link to clipboard
Copied
I have a dynamic list of events that is generated from the datebase. The client clicks on a link for an event in the list and the event name (eventName) and event Id (eventId) are sent to the log-in page as a URL var. This is what the link looks like on the dynamtic list page:
<a href="adminSignin2.php?eventId=<?php echo $row_rsEventList['eventId']; ?>&eventName=<?php echo $row_rsEventList['eventName']; ?>"><?php echo $row_rsEventList['eventName']; ?></a>
This shows up in the browser on the log-in page as:
adminSignin2.php?eventId=1&eventName=Jayhawk%20Invitational
The eventId is the primary key generated in the list of events in mySQL. So, I think the answer to your question is that the eventId and eventName are always same because each event only has one eventId.
As for the session question, I am not sure which option would be best. Once a person logs in, I only want them to be able to make changes in the database with respect to the eventName/eventId they log in for.
FYI - This is a website where sporting-event directors can log on and post scores for their event. Each administrator should only be able to make changes for their event (and have no access to any of the other eventName/eventId's).
Any ideas or suggestions you might have on what might be the best way to control this type of access would be greatly appreciated.

Copy link to clipboard
Copied
This one seems pretty straight-forward then. Since URL params are consistent and only their values change depending on event selected I would add a simple code on adminSignin2.php that checks to see if URL params are set and if they are then assign their values to session variables. Something like this:
<?php
// start a session on the page
session_start();
// check to see if eventId is set and a value exists and make sure eventName is set and a value exits for it as well
if (isset($_GET['eventId']) && $_GET['eventId'] != "" && isset($_GET['eventName']) $_GET['everntName'] != "") {
// if the conditions are true then set session variables for eventId and eventName
$_SESSION['eventId'] = $_GET['eventId'];
$_SESSION['eventName'] = $_GET['eventName'];
// end the condition
}
// now let's check to see if the session variables have been set
if (isset($_SESSION['eventId']) && isset($_SESSION['']) {
// if the conditions are true then display the values of the session variables on the page
echo "event ID = ".$_SESSION['eventId'];
echo "<br />";
echo "event Name = ".&_SESSION['eventName'];
// end the condition
}
?>
Then in login processing check to make sure user attempting to login has authorization to access event ID and event Name by adding additional conditions into your login query to check if values of session variables that were set match values entered into table row for the user that's attempting to login. User login table would need 4 colums. 1 username, 1 pw, 1 eventid, one eventname. Then basics of the login query would SELECT username FROM logintable WHERE username = POST['username'] AND password = POST['password'] AND eventid = SESSION['eventId'] AND eventname = SESSION['eventName']. That's obviously not the right code, but hopefully you get the idea. The point being that you should check additional parameters in your login query to make sure user is allowed access to content they're attempting to login to. Then set a session variable for the username from the result of the query row. Make sure you sanitize your variables that are going into MySQL query to prevent injection attacks that could compromise your database.
A better way might be to just have one login page without all these links with url params going to login and determining where the user goes after that (if they're allowed). Just direct logged in user to their content depending on variables in their db table since that's more fool-proof. Not really sure how your whole system is setup though or what stage of development you're at to make a full recommendation regarding alternative development methods.
best,
Shocker
Copy link to clipboard
Copied
One small but important point I would add: Sanitize your GET variables. Shocker mentions this but doesn't give examples. For numbers, this is very easy. You can simply go. . .
if (is_numeric($_GET['event_id'])){
for strings, you can do something like this. . .
$_SESSION['eventName'] = preg_replace('/[^-a-zA-Z0-9_]/', '', $_GET['eventName']);
or, one I like to use, where I can, is. . .
if (ctype_alpha($_GET['page_type'])){
Also, use PDO or mysqli instead of mysql so you can use bound parameters

