mo_ib_bmw Posted September 10, 2007 Share Posted September 10, 2007 hi ,i want to know how i can do user group's in php & mysql ( user , modretor , admin ) and i know how i do regester page but i don't know how i can do group's to it ( group's ) and do page to chang type group to some user... Link to comment Share on other sites More sharing options...
Kristian_C Posted September 10, 2007 Share Posted September 10, 2007 i hope you can code HTML for i dont have time to do everything for you but i can code the PHP..registrer.php : <script type="text/javascript"> function DispTakenUser() //If the username is taken we display a alert box...{alert("Username is taken. Pleace try another one.")}</script><?phpif(isset($_POST['reg'])){ //name the submit button reg$user=$_POST['user']; //name the User textfield for user$pass=$_POST['pass']; //name the password textfield pass $email=$_POST['email']; //name the email textfield email$ip=$_SERVER['REMOTE_ADDR']; //get the ip address.$seluser=mysql_num_rows(mysql_query("SELECT user FROM users WHERE user='$user'")); //select usernameif(!$seluser=0){ //check the selected usernameecho"<script type=\"text/javascript\">history.back(); DispTakenUser();</script>"; //if the username is taken}else //if the username is avalible{mysql_query("INSERT INTO users( //insert the user to the MySQL database...id,user,password,email,ip,level)VALUES('','$user','$pass','$email','$ip','User')") or die("Error : " .mysql_error()); //show error if it comes upecho"Your account has been created. Login with your username and password"; //user created}?> make a login.php with textfield for username and password named user and pass, and a submit form button named login and the form action must be login_do.php and method postlogin_do.php : <script type=\"text/javascript\">function DispWronguserOrpass(){alert("The username or password is incorrect. Pleace try again")}</script><?phpif(isset($_POST['login'])){$user=$_POST['user'];$pass=$_POST['pass'];$seluser=mysql_query("SELECT user FROM users WHERE user='$user'"); //check user$check=mysql_num_rows($seluser);//check userif(!$check > 0){//check userecho"<script type=\"text/javascript\">history.back(); DispWronguserOrpass();</script>";//Display a message if user dont exist}$selpass=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE user='$user'")); //check passif($selpass!=$pass){ //checkpassecho"<script type=\"text/javascript\">history.back(); DispWronguserOrpass();</script>"; //Display a message if password is wrong}else //if everything is right{setcookie(user,$user,time()+3600); //he/she will now be online for 1hour$deltime=time()+3500;mysql_query("UPDATE users SET online='Yes' WHERE user='$user'"); //set user onlinemysql_query("UPDATE users SET delonline='$deltime' WHERE user='$user'"); //set the time when we will make the user to be automaticly logget out and set offlineheader("Location: your_user_protected_site.php"); //get the user to your site}} //login = done....?> now we need a little script for all pages : <?php$user=$_COOKIE['user']; //Get the cookie$usere=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE user='$user'")); //select things from userif($usere->delonline <= time()){ //if the user has been online for 3500secondsmysql_query("UPDATE users SET online='No' WHERE user='$user'");setcookie(user,$user,time()-3600); //set the cookie to be "gone" so the user can be set offline and logged out..header("Location: the_site_where_you_want_him_to_go.php");}?> So the only thing you need now is to set up the table users :id int(30) auto_increment primary key the user iduser varchar(15) the user namepass varchar(40) the passwordemail varchar(60) the emailip varchar(20) the ip addressonline enum('No','Yes') onlinedelonline varchar(30) delete online level enum('User','Moderator','Administrator') // userlevelthink that was everything, hope this will help you... if not im sure some other guys can help you more .. so now you can set the userlevel direct from the MySQL db, or you can read abit about the $_POST[] functions and mysql_update / select in the wonderful world of w3schools.com-Kristian_C Link to comment Share on other sites More sharing options...
mo_ib_bmw Posted September 10, 2007 Author Share Posted September 10, 2007 thank you very much for all thing and i waiting you or anyone to compleate your describtion to how i can do user group's Link to comment Share on other sites More sharing options...
Kristian_C Posted September 10, 2007 Share Posted September 10, 2007 what kind of groups do you think about?, added userlevel there, as in user, mod, admin... do change level on urself you can go to the MySQL database and insert you or edit ur user and set userlevel to Administrator..to set others :admin.php <?php//insert the code i said you had to have on all sites...if(!$users->userlevel="Administrator"){ //block user if user aint adminecho"Only admins here mate";}else //if user is admin{?>//your html code here<?phpif(isset($_POST['makeadmin'])){$userto=$_POST['userto']; //make a textfield with the name userto here you insert the name of the users you want to make adminmysql_query("UPDATE users SET userlevel='Administrator' WHERE user='$userto'");echo"$userto is now admin";}//just duplicate the code to make users Moderator, just remember to change the userto and Administrator...} //end of code?> Hope thats what you need -Kristian_C Link to comment Share on other sites More sharing options...
Synook Posted September 11, 2007 Share Posted September 11, 2007 Basically if you have a database with the users' details you can just create an extra column with the user's type. Link to comment Share on other sites More sharing options...
mo_ib_bmw Posted September 11, 2007 Author Share Posted September 11, 2007 thanx very much Kristian_C for all thing , and now i want to know some thing :how i can to give each group's special powers 'control' by level enum Synook thank for reply ,but i don't know what you mean... Link to comment Share on other sites More sharing options...
Kristian_C Posted September 11, 2007 Share Posted September 11, 2007 Well what kind of site are you creating?....-Kristian_C Link to comment Share on other sites More sharing options...
Synook Posted September 11, 2007 Share Posted September 11, 2007 And what sort of format are you storing the user's details in? E.g. in a database, or in a flat file? Link to comment Share on other sites More sharing options...
mo_ib_bmw Posted September 11, 2007 Author Share Posted September 11, 2007 Well what kind of site are you creating?.... And what sort of format are you storing the user's details in? E.g. in a database, or in a flat file?hi,i want to do script upload and i want do 3 group's in it :visitor -> don't have control panel , and can be upload file to 1 Mbuser -> he have control panel to save his file in it , and can be uploaded to 10 Mbadmin -> he have control panel , he can edit setting of user's and file's , and he can uploaded to 25 Mb thanx... Link to comment Share on other sites More sharing options...
Kristian_C Posted September 11, 2007 Share Posted September 11, 2007 ok, just change the max file upload value to $max frist, then you add this code right afther the code i gave you : if($usere->userlevel=="User"){ // if User$max="1000000"; //think it is 10mb :p.} elseif($usere->userlevel=="Administrator"){ //if Admin$max ="2500000";} else{$max="100000"; //if visitor.} to be able to change stuff for users, just read about post and get functions and some MySQL...-Kristian_C. Link to comment Share on other sites More sharing options...
mo_ib_bmw Posted September 11, 2007 Author Share Posted September 11, 2007 thank you Kristian_C very much,i will trying do it and i will reply what i did...thank you for all thing again Link to comment Share on other sites More sharing options...
Kristian_C Posted September 11, 2007 Share Posted September 11, 2007 No problem :)Im allmost on every day 24/7 so ill be here to answer questions ...-Kristian_C Link to comment Share on other sites More sharing options...
Synook Posted September 12, 2007 Share Posted September 12, 2007 Uh... 2500000 is 2.5 MB, 1000000 bytes is 1 megabyte, and 100000 is 100 kb... the code should be if($usere->userlevel=="User"){ // if User$max="10000000"; //THIS is 10mb :D} elseif($usere->userlevel=="Administrator"){ //if Admin$max ="25000000";} else{$max="1000000"; //if visitor.} Link to comment Share on other sites More sharing options...
Kristian_C Posted September 12, 2007 Share Posted September 12, 2007 Hehe ... well seems like i need to get abit more into the file thing ... never used it before, wanted to be able to something sometime not so many weeks ago, but dident need it ..thanks for the info Synook ... Link to comment Share on other sites More sharing options...
justsomeguy Posted September 12, 2007 Share Posted September 12, 2007 Well if you want to be technical about it, 1MB = 220 = 1048576 bytes, making 10MB = 10485760 bytes and 25MB = 26214400 bytes. Link to comment Share on other sites More sharing options...
Synook Posted September 12, 2007 Share Posted September 12, 2007 SIGH... lol Link to comment Share on other sites More sharing options...
mo_ib_bmw Posted September 13, 2007 Author Share Posted September 13, 2007 thank's very much Synook and justsomeguy for the info Link to comment Share on other sites More sharing options...
Diegar Posted September 15, 2007 Share Posted September 15, 2007 Well if you want to be technical about it, 1MB = 220 = 1048576 bytes, making 10MB = 10485760 bytes and 25MB = 26214400 bytes.Or 1024 * 1024 = 1048576 for one megabyte.. heh Link to comment Share on other sites More sharing options...
mo_ib_bmw Posted September 17, 2007 Author Share Posted September 17, 2007 thanx Diegar....Kristian_C... while i use your step to do online and remmember the user by cookies i filed !!i mean with filed : don't remmember the user after do login !! Link to comment Share on other sites More sharing options...
Diegar Posted September 17, 2007 Share Posted September 17, 2007 thanx Diegar....Kristian_C... while i use your step to do online and remmember the user by cookies i filed !!i mean with filed : don't remmember the user after do login !!I am actually having similar issues with the script, but i am gonna keep plugging away at it for a while.Mine is telling me upon registration that the name is already taken, when it isn't, and when i enter one in manually, then try to log in with it, it hits the cookie code at the top of the member page, but go immediately to the 'logged out' page in the code. Seems that the cookie isn't taking, so the user always stays logged out. Link to comment Share on other sites More sharing options...
Diegar Posted September 18, 2007 Share Posted September 18, 2007 Okay, by changing if(!$seluser=0) to if($seluser!=0), i got the registration to work. It entered my info into the db. Woot! Still plugging away at the rest of it Link to comment Share on other sites More sharing options...
Diegar Posted September 19, 2007 Share Posted September 19, 2007 Okay... i have added some html into the script in hopes of finding where it went wrong during login. <script type=\"text/javascript">function DispWronguserOrpass(){alert("The username or password is incorrect. Pleace try again")}</script><?phprequire("dbconfig.php");?><table> <tr> <td> <font>Step 1</font> </td> </tr></table><?if(isset($_POST['login'])){?><table> <tr> <td> <font>Step 2</font> </td> </tr></table><?$user=$_POST['user'];$pass=$_POST['pass']; When i try to login, it now says Step 1, which it should, but never shows Step 2... So this line "if(isset($_POST['login'])){" is messing things up, but it might be something i am doing wrong in the form. Anyone have any clues to why this line would be messing me up? Link to comment Share on other sites More sharing options...
zppblood Posted September 19, 2007 Share Posted September 19, 2007 <script type=\"text/javascript"> - Remove the \ in it.Do you have some HTML element like the submit button named 'login'? Link to comment Share on other sites More sharing options...
Diegar Posted September 19, 2007 Share Posted September 19, 2007 <script type=\"text/javascript"> - Remove the \ in it.Do you have some HTML element like the submit button named 'login'?It only seems to get to the register.php page script if i name the form login, and not the submit button. If i name the form "log" and the submit button "login" (reverse), then when i try to login, i hit submit and it just refreshes the login screen. It doesn't go any further than that.let me know if i need to include more info, cause i am lost in this. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 19, 2007 Share Posted September 19, 2007 Post the code for the form you're using. Any form element named login will have an entry in $_POST. I use hidden inputs to send information like that. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.