Forum Moderators: coopster
I have a membership system to manage my membership site written in perl. The pages on the members site are in php with a MySQL backend. The pages are also dynamically generated.
What I am trying to do is capture the username when the user logs in so that I know which record to display on the page. Sounds simple enough but I can't get it to work.
The membership program supposedly passes a cookie as the username. This is what I have in the index.php page when the user logs in.
Thanks in advance for your help.
<?php
require('db_spec.php');
$option_sql = new DB("$dbhost", "$dbuser", "$dbpass", "$db");
if (!$option_sql->open())
{
die($option_sql->error());
}
echo "SELECT * FROM userinfo where Username=".$_COOKIE["$mojousn"];
if (!$option_sql->query("SELECT * FROM userinfo where Username=".$_COOKIE["$mojousn"]))
{
die($option_sql->error());
}
$option_row = $option_sql->fetchAssoc();
?>
Maybe the var in the cookie is incorrect? This is where the membership program looks to be setting the cookie. Can I call $mj{mem70} in php?
$MEMBER{username} = $MEMBER{password} = $FORM{step} = "";
$CONFIG{setcookie_now}=1;
&MemberLogin($mj{mem70});
For instance if I changed my cookie so my username was ' or '' == ' then the SQL would become..
SELECT * FROM userinfo where Username='' or '' == ''
which might let me into your system.
You should at least use addslashes() on the cookie data first.
A user goes to the login page and logs in. They hit the membership program where they are redirected to the index.php page. That's fine until I decided to dynamically generate content on the index page. So I need some way for the code to take the username that is entered in the login form and hold on to it so it knows which record to call.
How would you do this?
But I'd also be careful to validate the data from the login form before I used it to select against the database.
For example if I only expected usernames to contain alphanumeric characters then I'd check that before I did any checking against the database.
If I was allowing more complicated usernames then I'd use either addslashes() or htmlentities() on it to get rid of any dodgy characters.
Hope that helps.