unsider Posted February 21, 2008 Share Posted February 21, 2008 Ok, I have been attempting to do a pretty simple task for the last little while, and unfortunately I've failed miserably. I am trying to: Establish the main section of website: index.php I need a registration page: register.php I need a login script that process my login info: login.php I need a script that destroys existinging mess: logout.php register.php (register with forms, no problem inputing into DB), if successful redirect to: index.php (contains log in forms, enter info, action="login.php") login.php(process the information, and if successful redirect back to index.php) With a message displaying you are logged in, giving you the option to log out. (logout is pressed, redirected to logout.php) logout.php then once destroying redirects once again to index.php with everything cleared displaying you are no longer logged in. I have tried, but I've failed, here are the scripts I've been using, please feel free to edit so they are efficent, and work correctly. Note: database contains: id, username, password, email. The include file is the db connect, so don't worry about any of that. If you have the time to help a poor soul out, I'd much appreciate it. Thanks. index.php <title>rhythmic design</title><?php session_start(); if (!$_SESSION["valid_user"]) { Header("Location: login.php"); } echo "<p>User ID: " . $_SESSION["valid_id"]; echo "<p>Username: " . $_SESSION["valid_user"]; echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]); echo "<p><a href=\"logout.php\">Click here to logout!</a></p>"; ?> register.php <?php include ("db_connect.inc.php"); if ( $_GET["op"] == "reg" ) { $bInputFlag = false; foreach ( $_POST as $field ) { if ($field == "") { $bInputFlag = false; } else { $bInputFlag = true; } } if ($bInputFlag == false) { die( "Problem with your registration info. " ."Please go back and try again."); } $q = "INSERT INTO `members` (`username`,`password`,`email`) " ."VALUES ('".$_POST["username"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; $r = mysql_query($q); if ( !mysql_insert_id() ) { die("Error: User not added to database."); } else { Header("Location: index.php"); } } elseif ( $_GET["op"] == "thanks" ) { echo "<h2>Thanks for registering!</h2>"; } else { echo "<form action=\"?op=reg\" method=\"POST\">\n"; echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n"; echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n"; echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n"; echo "<input type=\"submit\">\n"; echo "</form>\n"; } ?> login.php <?php session_start(); include "db_connect.inc.php"; if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } $q = "SELECT * FROM `members` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; $r = mysql_query($q); if ( $obj = @mysql_fetch_object($r) ) { $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["username"]; $_SESSION["valid_time"] = time(); Header("Location: index.php"); } else { die("Sorry, could not log you in. Wrong login information."); } } else { echo "<form action=\"?op=login\" method=\"POST\">"; echo "Username: <input name=\"username\" size=\"15\"><br />"; echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />"; echo "<input type=\"submit\" value=\"Login\">"; echo "</form>"; } ?> logout.php <?php session_start(); session_unset(); session_destroy(); Header("Location: index.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/ Share on other sites More sharing options...
cooldude832 Posted February 21, 2008 Share Posted February 21, 2008 and the problem is??? Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/#findComment-472462 Share on other sites More sharing options...
unsider Posted February 21, 2008 Author Share Posted February 21, 2008 I changed back to the scripts that functioned propery. registration->login->index->logout->login but unfortunately that's not what i wanted, and im not sure how to change it to function properly. Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/#findComment-472465 Share on other sites More sharing options...
cooldude832 Posted February 21, 2008 Share Posted February 21, 2008 not functioning properly isn't very clear and no one gonna read through it for you if u don't clarify the issue Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/#findComment-472468 Share on other sites More sharing options...
mariocesar Posted February 21, 2008 Share Posted February 21, 2008 I have tried, but I've failed, here are the scripts I've been using, please feel free to edit so they are efficent, and work correctly. Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/#findComment-472469 Share on other sites More sharing options...
unsider Posted February 21, 2008 Author Share Posted February 21, 2008 not functioning properly isn't very clear and no one gonna read through it for you if u don't clarify the issue register.php (register with forms, no problem inputing into DB), if successful redirect to: index.php (contains log in forms, enter info, action="login.php") login.php(process the information, and if successful redirect back to index.php) With a message displaying you are logged in, giving you the option to log out. (logout is pressed, redirected to logout.php) logout.php then once destroying redirects once again to index.php with everything cleared displaying you are no longer logged in. That's my problem, thats what I'm attempting to do. Sorry if I wasn't clear enough, hard to ask a question when the scripts work, but not the way i want them too Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/#findComment-472473 Share on other sites More sharing options...
cooldude832 Posted February 21, 2008 Share Posted February 21, 2008 so what goes wrong then or have u not tried it assuming it goes wrong. Do pigs start flying out of your monitor when u run it? Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/#findComment-472476 Share on other sites More sharing options...
unsider Posted February 21, 2008 Author Share Posted February 21, 2008 When I tried to change it to the functionality I wanted I ended up having problems trying to redirect back to the index.php without any errors. I wish I would have saved some of the errors, but basically it did not follow the path I would have liked. I'm just seeing if I need to clarify more things, do you know what I'm trying to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/#findComment-472477 Share on other sites More sharing options...
unsider Posted February 21, 2008 Author Share Posted February 21, 2008 I know it takes time, but I'd really appreciate the help. I need it. Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/#findComment-472504 Share on other sites More sharing options...
cooldude832 Posted February 21, 2008 Share Posted February 21, 2008 well if you can't articulate the "errors" to us I guess you can't be helped. Quote Link to comment https://forums.phpfreaks.com/topic/92228-in-need-of-help/#findComment-472667 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.