in all pages will code with "session_start ();"
but does not display all the information,
as "First name, Last name"
But if the user is connected,
and when browsing pages,
only shows the nick, and the other names disappear
on the first page to connect,
if it shows all the user information
but when clicking to another page disappears
please help, how to solve
or correct the problem.
"$cedula" is the nickname,
"$clave" is the password
Here, the full code
Funtions.php
<?
function loginuser()
{
$cedula = $_POST['cedula'];
$clave = $_POST['clave'];
$nombres = $_POST['nombres'];
$nombres = $_GET['nombres'];
if ($cedula && $clave)
{
include_once('adodb/adodb.inc.php');
include_once('conn.php'); // Coneción
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$conn = &ADONewConnection('mysql');
$conn->Connect($dbhost,$dbuser,$dbpass,$dbdatabase);
$pass = md5($clave);
$uname = capotexto($cedula);
$sqlstmt = "SELECT role FROM personas WHERE cedula='$uname' AND clave='$pass'";
$recordSet = &$conn->Execute("$sqlstmt");
$numResults = $recordSet->RecordCount();
$userRole = $recordSet->fields['role'];
if ($numResults > 0)
{
$_SESSION['auth_user'] = $cedula;
$_SESSION['auth_role'] = $userRole;
}
else
{
$page = new pagebuilder('../');
//
echo "<div align=center> $cedula. no es correcto <a href='javascript:history.go(-1);'>Volver</a></div>";
exit;
}
}
else
{
$page = new pagebuilder('../');
//
echo "<div align=center> Usuario y Contraseña. <a href='javascript:history.go(-1);'>Volver</a></div>";
exit;
}
}
function checkUser($check='')
{
if (!isset($_SESSION['auth_user']))
{
$page = new pagebuilder('../');
//
echo "<div align=center> aun no se ha logeado </div><br>";
echo "<div align=center> <a href='javascript:history.go(-1);'>Volver</a></div>";
exit;
}
if ($check)
{
if ($_SESSION['auth_role'] != $check)
{
$page = new pagebuilder('../');
//
echo "<div align=center> no tienes permiso!<br></div>";
exit;
}
}
}
?>
PagesHome1.php, PageHome2.php etc.
<?php
session_start();
if (!isset($_SESSION['auth_user'])) loginuser();
include_once('funtion.php');
include_once('conn.php'); // Coneción
mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
mysql_select_db($dbdatabase) or die(mysql_error());
// Esto por si las dudas
$_SESSION['cedula'] = $_POST['cedula'];
$_SESSION['personasid'] = $_POST['personasid'];
$_SESSION['nombres'] = $_POST['nombres'];
$_SESSION['apellidos'] = $_POST['apellidos'];
$result = mysql_query("SELECT * FROM personas WHERE cedula='".$_SESSION["cedula"]."' ");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$personasid = $row['personasid'];
$nombres = $row['nombres'];
$apellidos = $row['apellidos'];
}
//
?>
<?php if (isset($_SESSION['auth_user'])) { ?>
Welcome! <? echo $nombres; ?> <? echo $apellidos; ?>
Nick <? echo ' '.$_SESSION['auth_user']; ?>
ID <? echo $personasid; ?>
<? } ?>
`<form action="PagesHome1.php" method="POST">
<input name="cedula" type="text" />
<input name="clave" type="password" />
<input name="Entrar" type="submit">
</form>
SQL Table
Código HTML:
CREATE TABLE personas
(personasid
int(11) NOT NULL AUTO_INCREMENT,cedula
varchar(40) NOT NULL DEFAULT '',clave
varchar(40) NOT NULL DEFAULT '',email
varchar(60) DEFAULT NULL,role
varchar(20) default NULL,nombres
varchar(100) NOT NULL DEFAULT '',apellidos
varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (personasid
),
UNIQUE KEY cedula
(cedula
)
) ;`