joeysarsenal Posted October 22, 2007 Share Posted October 22, 2007 i want my page to redirect to another page after a successfull login. Just not sure what command to use. below is the code im working with <?php require_once('auth.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Member Index</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Welcome to Members' area!</h1> <a href="member-profile.php">My Profile</a> | <a href="logout.php">Logout</a> | <a href="http://localhost/Finalised/Loginsucces1.htm">Contiue with Priviladges</a> <p>This is a password protected area only accessible to members. </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/ Share on other sites More sharing options...
corillo181 Posted October 22, 2007 Share Posted October 22, 2007 are you keeping the user data in mysql? do you have a form? Quote Link to comment https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/#findComment-375259 Share on other sites More sharing options...
SammyGunnz Posted October 22, 2007 Share Posted October 22, 2007 In the page you're posting to you can do something like this... <?php if(isset($_POST['login'])) { //Send the login info in an array to a method in your class that scrubs it, //cleans it, escapes invalid characters, and checks it. Return true if it all checks out and then redirect them to main.php //....Or whatever approach you want to take if($check->($login_array) == true) { header("location: main.php"); exit; } } ?> There's different ways of approaching it. Look at the header() function. Quote Link to comment https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/#findComment-375261 Share on other sites More sharing options...
corillo181 Posted October 22, 2007 Share Posted October 22, 2007 wow Sammy the guy is asking about redirecting and you are responding with a class involve. nice way to help. Quote Link to comment https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/#findComment-375264 Share on other sites More sharing options...
joeysarsenal Posted October 22, 2007 Author Share Posted October 22, 2007 yer the data is in a database table and im using a form to get to that page but at that page i want it to rederect after a minute or so. Quote Link to comment https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/#findComment-375284 Share on other sites More sharing options...
joeysarsenal Posted October 22, 2007 Author Share Posted October 22, 2007 im really stuck guys i even tried html Quote Link to comment https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/#findComment-375296 Share on other sites More sharing options...
JJohnsenDK Posted October 22, 2007 Share Posted October 22, 2007 could you post your login script? Quote Link to comment https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/#findComment-375298 Share on other sites More sharing options...
joeysarsenal Posted October 22, 2007 Author Share Posted October 22, 2007 sure script is below <?php //Start session session_start(); //Connect to mysql server $link=mysql_connect("localhost","root",""); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db=mysql_select_db("plaincart"); if(!$db) { die("Unable to select database"); } //Sanitize the value received from login field //to prevent SQL Injection if(!get_magic_quotes_gpc()) { $login=mysql_real_escape_string($_POST['login']); }else { $login=$_POST['login']; } //Create query $qry="SELECT member_id FROM Emps WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result)>0) { //Login Successful session_regenerate_id(); $member=mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID']=$member['member_id']; session_write_close(); header("location: member-index.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/#findComment-375300 Share on other sites More sharing options...
yzerman Posted October 22, 2007 Share Posted October 22, 2007 Maybe I missed something, but how is your code failing? Quote Link to comment https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/#findComment-375314 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.