par
Driamar » 08 avr. 2013, 16:37
Code : Tout sélectionner
<?php require_once('Connections/MaConnexion.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
$isValid = False;
if (!empty($UserName)) {
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "register.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?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;
}
}
$maxRows_manga = 10;
$pageNum_manga = 0;
if (isset($_GET['pageNum_manga'])) {
$pageNum_manga = $_GET['pageNum_manga'];
}
$startRow_manga = $pageNum_manga * $maxRows_manga;
mysql_select_db($database_MaConnexion, $MaConnexion);
$query_manga = "SELECT * FROM manga WHERE id_utilisateur='".$_SESSION['id_utilisateur']."' ORDER BY nom_auteur ASC";
$query_limit_manga = sprintf("%s LIMIT %d, %d", $query_manga, $startRow_manga, $maxRows_manga);
$manga = mysql_query($query_limit_manga, $MaConnexion) or die(mysql_error());
$row_manga = mysql_fetch_assoc($manga);
if (isset($_GET['totalRows_manga'])) {
$totalRows_manga = $_GET['totalRows_manga'];
} else {
$all_manga = mysql_query($query_manga);
$totalRows_manga = mysql_num_rows($all_manga);
}
$totalPages_manga = ceil($totalRows_manga/$maxRows_manga)-1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Document sans titre</title>
</head>
<body>
<table border="1">
<tr>
<td>nom_manga</td>
<td>id_utilisateur</td>
<td>nom_auteur</td>
<td>nom_editeur</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_manga['nom_manga']; ?></td>
<td><?php echo $row_manga['id_utilisateur']; ?></td>
<td><?php echo $row_manga['nom_auteur']; ?></td>
<td><?php echo $row_manga['nom_editeur']; ?></td>
</tr>
<?php } while ($row_manga = mysql_fetch_assoc($manga)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($manga);
?>
Voici le code de ma page !
Entre temps, j'ai réussi à restreindre l'accès à la page.
Lorsque je met la requête au niveau du tableau afin qu'il ne m'affiche uniquement les enregistrements selon l'utilsateur dont la session est en cours il me met une erreur.
Et je ne vois pas du tout comment la corriger. Aurais-je oublié une variable ou fait une fausse manip ?
merci encore pour votre aide !
[code]<?php require_once('Connections/MaConnexion.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
$isValid = False;
if (!empty($UserName)) {
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "register.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?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;
}
}
$maxRows_manga = 10;
$pageNum_manga = 0;
if (isset($_GET['pageNum_manga'])) {
$pageNum_manga = $_GET['pageNum_manga'];
}
$startRow_manga = $pageNum_manga * $maxRows_manga;
mysql_select_db($database_MaConnexion, $MaConnexion);
$query_manga = "SELECT * FROM manga WHERE id_utilisateur='".$_SESSION['id_utilisateur']."' ORDER BY nom_auteur ASC";
$query_limit_manga = sprintf("%s LIMIT %d, %d", $query_manga, $startRow_manga, $maxRows_manga);
$manga = mysql_query($query_limit_manga, $MaConnexion) or die(mysql_error());
$row_manga = mysql_fetch_assoc($manga);
if (isset($_GET['totalRows_manga'])) {
$totalRows_manga = $_GET['totalRows_manga'];
} else {
$all_manga = mysql_query($query_manga);
$totalRows_manga = mysql_num_rows($all_manga);
}
$totalPages_manga = ceil($totalRows_manga/$maxRows_manga)-1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Document sans titre</title>
</head>
<body>
<table border="1">
<tr>
<td>nom_manga</td>
<td>id_utilisateur</td>
<td>nom_auteur</td>
<td>nom_editeur</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_manga['nom_manga']; ?></td>
<td><?php echo $row_manga['id_utilisateur']; ?></td>
<td><?php echo $row_manga['nom_auteur']; ?></td>
<td><?php echo $row_manga['nom_editeur']; ?></td>
</tr>
<?php } while ($row_manga = mysql_fetch_assoc($manga)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($manga);
?>
[/code]
Voici le code de ma page !
Entre temps, j'ai réussi à restreindre l'accès à la page.
Lorsque je met la requête au niveau du tableau afin qu'il ne m'affiche uniquement les enregistrements selon l'utilsateur dont la session est en cours il me met une erreur.
Et je ne vois pas du tout comment la corriger. Aurais-je oublié une variable ou fait une fausse manip ?
merci encore pour votre aide !