Jump to content
Fórum Script Brasil
  • 0

Dúvida, Form Login.


3dmaniaco

Question

Tranquilo Pessoal ?

Eu possuo um form de login, onde o formulario compara o username e a senha com o banco mysql, e caso seja afirmativo, redireciona para a pagina painel.php.

Mas eu gostaria que quando formulario fizesse o login, ele enviasse o ID do usuário que esta fazendo login, e envie pela url o parametro ID.

A url ficaria assim pagina.php?id=1

Esse é o meu formulário, de login, que eu fiz pelo dreamweaver cs4

<?php require_once('../Connections/Abyara.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_Abyara, $Abyara);
$query_RsListar = "SELECT * FROM cadastro ORDER BY id_cadastro ASC";
$RsListar = mysql_query($query_RsListar, $Abyara) or die(mysql_error());
$row_RsListar = mysql_fetch_assoc($RsListar);
$totalRows_RsListar = mysql_num_rows($RsListar);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['senha'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "adicionar.php";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_Abyara, $Abyara);
  
  $LoginRS__query=sprintf("SELECT username, senha FROM cadastro WHERE username=%s AND senha=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $Abyara) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;          

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  <table width="100" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><label>
        <input type="text" name="username" id="username" />
      </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><label>
        <input type="text" name="senha" id="senha" />
      </label></td>
    </tr>
    <tr>
      <td><input type="submit" name="button" id="button" value="Login" /></td>
    </tr>
  </table>
</form>
</body>
</html>
<?php
mysql_free_result($RsListar);
?>

Já tentei fazer de varias formas, mas não deu certo, como posso fazer ?

Desde já, muito obrigado.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Primeiramente ESerra, obrigado pelo retorno.

ESerra, estou tentando alterar aqui, mas não estou conseguindo resolver, se não for pedir muito, você não me faria alteração, para eu entender a lógica, pois ainda estou aprendendo, e eu preciso fazer esse form para aprender.

Se puder colaborar, agradeço desde já.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...