I don't understand why you're giving a registering user the choice of which level to enter - surely this is a security flaw?
If this is a publically viewable form, it could be easily spoofed in order to send data with 'admin' enabled/selected.
I was going to post the code, but then, I saw your reply. Try it yourself first - don't be lazy! :)
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
If you tried, show us what you got. This is a help forum, not a free lunch forum.
If the form is only for an admin to fill out, I don't see why you need the admin radio option in the first place, as he/she will have registered as an admin SOMEHOW already.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
how about:
<?php
if(!admin_exists){
echo '<input name="level" id="adminlevel" type="radio" value="2" /> <label for="adminlevel">admin</label>';
}
?>
<input name="level" id="manlevel" type="radio" value="1" /> <label for="manlevel">manager</label>
<input name="level" id="employeelevel" type="radio" value="0" /> <label for="employeelevel">employee</label>
That should work for a secured form (if only an admin can get at it). HOWEVER, using plaintext or integer values is dangerous if not, as anybody can spoof a form and send it as an admin (even if they're not).
One way to prevent this is to hash the values with something like this:
$adminhash = md5('thisisadmin97531');
// so then
if(!admin_exists){
echo '<input name="level" id="adminlevel" type="radio" value="' . $adminhash . '" /> <label for="adminlevel">admin</label>';
}
You then need to check on form handling for $_POST['level'] - use a switch or if/elseif/else... to check for accepted values, which are:
eb9ef3335cf3726752e8008b5bbe9b74 (admin)
1 (manager)
0 (employee)
But this is pretty hypothetical as we don't know HOW this is being used. As I said, individuals should never be allowed to enter their level of access/rights/permissions.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
I agree this is going to cause serious problems allowing users to be any level they wish!!!! The site will not last more than a week online with that security!!!
mikulucky
Junior Poster in Training
85 posts since Jan 2012
Reputation Points: 41
Solved Threads: 13
Before you ask any more questions about the code. Answer my question - how is this going to be used and by whom? This will enable us to answer you correctly. At the moment I can only guess at what you wish to achieve.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080