Jump to content

Redirecting After Successfull Login


joeysarsenal

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/74276-redirecting-after-successfull-login/
Share on other sites

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.

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");
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.