Problème avec script PHP
zeckiis
Messages postés
225
Statut
Membre
-
Fallentree Messages postés 2445 Statut Membre -
Fallentree Messages postés 2445 Statut Membre -
Bonjour,
j'ai télécharger un script de e-comerce depuis ce site:
http://www6.phpwebcommerce.com/?tdfs=1&kw=Ecommerce+Software&term=Ecommerce%20Shopping%20Cart%20Platform&term=Ecommerce%20Online%20Store&term=Digital%20Marketing%20Services&backfill=0
cependant j'ai des soucis pour me connecter à la partie admin: voici le script qui gére la connexion:
___________________________________________
function checkUser()
{
// if the session id is not set, redirect to login page
if (!isset($_SESSION['plaincart_user_id'])) {
header('Location: ' . WEB_ROOT . 'admin/login.php');
exit;
}
// the user want to logout
if (isset($_GET['logout'])) {
doLogout();
}
}
/*
*/
function doLogin()
{
// if we found an error save the error message in this variable
$errorMessage = '';
$userName = $_POST['txtUserName'];
$password = $_POST['txtPassword'];
// first, make sure the username & password are not empty
if ($userName == '') {
$errorMessage = 'You must enter your username';
} else if ($password == '') {
$errorMessage = 'You must enter the password';
} else {
// check the database and see if the username and password combo do match
$sql = "SELECT user_id
FROM tbl_user
WHERE user_name = '$userName' AND user_password = PASSWORD('$password')";
$result = dbQuery($sql);
if (dbNumRows($result) == 1) {
$row = dbFetchAssoc($result);
$_SESSION['plaincart_user_id'] = $row['user_id'];
// log the time when the user last login
$sql = "UPDATE tbl_user
SET user_last_login = NOW()
WHERE user_id = '{$row['user_id']}'";
dbQuery($sql);
// now that the user is verified we move on to the next page
// if the user had been in the admin pages before we move to
// the last page visited
if (isset($_SESSION['login_return_url'])) {
header('Location: ' . $_SESSION['login_return_url']);
exit;
} else {
header('Location: index.php');
exit;
}
} else {
$errorMessage = 'Wrong username or password';
}
}
return $errorMessage;
}
___________________________________________
j'aimerai savoir où se trouve le souci, ou bien comment contournercette page. J'ai bien vérifier la base données avec les identifiants : admin - admin.
merci
j'ai télécharger un script de e-comerce depuis ce site:
http://www6.phpwebcommerce.com/?tdfs=1&kw=Ecommerce+Software&term=Ecommerce%20Shopping%20Cart%20Platform&term=Ecommerce%20Online%20Store&term=Digital%20Marketing%20Services&backfill=0
cependant j'ai des soucis pour me connecter à la partie admin: voici le script qui gére la connexion:
___________________________________________
function checkUser()
{
// if the session id is not set, redirect to login page
if (!isset($_SESSION['plaincart_user_id'])) {
header('Location: ' . WEB_ROOT . 'admin/login.php');
exit;
}
// the user want to logout
if (isset($_GET['logout'])) {
doLogout();
}
}
/*
*/
function doLogin()
{
// if we found an error save the error message in this variable
$errorMessage = '';
$userName = $_POST['txtUserName'];
$password = $_POST['txtPassword'];
// first, make sure the username & password are not empty
if ($userName == '') {
$errorMessage = 'You must enter your username';
} else if ($password == '') {
$errorMessage = 'You must enter the password';
} else {
// check the database and see if the username and password combo do match
$sql = "SELECT user_id
FROM tbl_user
WHERE user_name = '$userName' AND user_password = PASSWORD('$password')";
$result = dbQuery($sql);
if (dbNumRows($result) == 1) {
$row = dbFetchAssoc($result);
$_SESSION['plaincart_user_id'] = $row['user_id'];
// log the time when the user last login
$sql = "UPDATE tbl_user
SET user_last_login = NOW()
WHERE user_id = '{$row['user_id']}'";
dbQuery($sql);
// now that the user is verified we move on to the next page
// if the user had been in the admin pages before we move to
// the last page visited
if (isset($_SESSION['login_return_url'])) {
header('Location: ' . $_SESSION['login_return_url']);
exit;
} else {
header('Location: index.php');
exit;
}
} else {
$errorMessage = 'Wrong username or password';
}
}
return $errorMessage;
}
___________________________________________
j'aimerai savoir où se trouve le souci, ou bien comment contournercette page. J'ai bien vérifier la base données avec les identifiants : admin - admin.
merci
A voir également:
- Problème avec script PHP
- Script vidéo youtube - Guide
- Easy php - Télécharger - Divers Web & Internet
- Ghost script - Télécharger - Polices de caractères
- Mas script - Accueil - Windows
- Expert php pinterest - Télécharger - Langages
13 réponses
WEB_ROOT et autre variable sont bien a jour.
verifie que tous tes fichiers d administration sont bien dans le repertoire racine.
Souvant les bout de code ne sont adapter au sous repertoires...
verifie que tous tes fichiers d administration sont bien dans le repertoire racine.
Souvant les bout de code ne sont adapter au sous repertoires...
j'ai ce bout de cote sur WEBROOT sur un fichier confih.php:
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];
j'ai essayé de mettre le chemin racine du site en local, mais ca m'a généré une erreur. je sais pas quoi mettre. cependant tous les fichiers sont bien en place. Le doute que j'ai se situe sur WEBROOT.
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];
j'ai essayé de mettre le chemin racine du site en local, mais ca m'a généré une erreur. je sais pas quoi mettre. cependant tous les fichiers sont bien en place. Le doute que j'ai se situe sur WEBROOT.
en admettant ...
Ta base est bien connecté :$connex = mysqli_connect($serveur, $user, $passwd, $bdd);
Ta base est bien connecté :$connex = mysqli_connect($serveur, $user, $passwd, $bdd);
voila le script que j'ai dans le fichier config.php:
<?php
ini_set('display_errors', 'On');
//ob_start("ob_gzhandler");
error_reporting(E_ALL);
// start the session
session_start();
// database connection config
$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = '';
$dbName = 'shopper';
// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot = str_replace('library/config.php', '', $thisFile);
define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);
// these are the directories where we will store all
// category and product images
define('CATEGORY_IMAGE_DIR', 'images/category/');
define('PRODUCT_IMAGE_DIR', 'images/product/');
// some size limitation for the category
// and product images
// all category image width must not
// exceed 75 pixels
define('MAX_CATEGORY_IMAGE_WIDTH', 75);
// do we need to limit the product image width?
// setting this value to 'true' is recommended
define('LIMIT_PRODUCT_WIDTH', true);
// maximum width for all product image
define('MAX_PRODUCT_IMAGE_WIDTH', 300);
// the width for product thumbnail
define('THUMBNAIL_WIDTH', 75);
if (!get_magic_quotes_gpc()) {
if (isset($_POST)) {
foreach ($_POST as $key => $value) {
$_POST[$key] = trim(addslashes($value));
}
}
if (isset($_GET)) {
foreach ($_GET as $key => $value) {
$_GET[$key] = trim(addslashes($value));
}
}
}
// since all page will require a database access
// and the common library is also used by all
// it's logical to load these library here
require_once 'database.php';
require_once 'common.php';
// get the shop configuration ( name, addres, etc ), all page need it
$shopConfig = getShopConfig();
?>
<?php
ini_set('display_errors', 'On');
//ob_start("ob_gzhandler");
error_reporting(E_ALL);
// start the session
session_start();
// database connection config
$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = '';
$dbName = 'shopper';
// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot = str_replace('library/config.php', '', $thisFile);
define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);
// these are the directories where we will store all
// category and product images
define('CATEGORY_IMAGE_DIR', 'images/category/');
define('PRODUCT_IMAGE_DIR', 'images/product/');
// some size limitation for the category
// and product images
// all category image width must not
// exceed 75 pixels
define('MAX_CATEGORY_IMAGE_WIDTH', 75);
// do we need to limit the product image width?
// setting this value to 'true' is recommended
define('LIMIT_PRODUCT_WIDTH', true);
// maximum width for all product image
define('MAX_PRODUCT_IMAGE_WIDTH', 300);
// the width for product thumbnail
define('THUMBNAIL_WIDTH', 75);
if (!get_magic_quotes_gpc()) {
if (isset($_POST)) {
foreach ($_POST as $key => $value) {
$_POST[$key] = trim(addslashes($value));
}
}
if (isset($_GET)) {
foreach ($_GET as $key => $value) {
$_GET[$key] = trim(addslashes($value));
}
}
}
// since all page will require a database access
// and the common library is also used by all
// it's logical to load these library here
require_once 'database.php';
require_once 'common.php';
// get the shop configuration ( name, addres, etc ), all page need it
$shopConfig = getShopConfig();
?>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
admin est inscrit dans une base de données et il est le seul a avoir tous les priviléges. Admin faisait parti de la table que j'ai importer et qui faisait parti du script:. Voila la structure:
_____________________________________
DROP TABLE IF EXISTS 'tbl_user';
CREATE TABLE 'tbl_user' (
'user_id' int(10) unsigned NOT NULL auto_increment,
'user_name' varchar(20) NOT NULL default '',
'user_password' varchar(32) NOT NULL default '',
'user_regdate' datetime NOT NULL default '0000-00-00 00:00:00',
'user_last_login' datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY ('user_id'),
UNIQUE KEY 'user_name' ('user_name')
) TYPE=MyISAM AUTO_INCREMENT=4 ;
--
-- Dumping data for table 'tbl_user'
--
INSERT INTO 'tbl_user' ('user_id', 'user_name', 'user_password', 'user_regdate', 'user_last_login') VALUES (1, 'admin', '43e9a4ab75570f5b', '2005-02-20 17:35:44', '2005-03-02 21:00:14');
INSERT INTO 'tbl_user' ('user_id', 'user_name', 'user_password', 'user_regdate', 'user_last_login') VALUES (3, 'webmaster', '026cf3fc6e903caf', '2005-03-02 17:52:51', '0000-00-00 00:00:00');
_____________________________________
_____________________________________
DROP TABLE IF EXISTS 'tbl_user';
CREATE TABLE 'tbl_user' (
'user_id' int(10) unsigned NOT NULL auto_increment,
'user_name' varchar(20) NOT NULL default '',
'user_password' varchar(32) NOT NULL default '',
'user_regdate' datetime NOT NULL default '0000-00-00 00:00:00',
'user_last_login' datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY ('user_id'),
UNIQUE KEY 'user_name' ('user_name')
) TYPE=MyISAM AUTO_INCREMENT=4 ;
--
-- Dumping data for table 'tbl_user'
--
INSERT INTO 'tbl_user' ('user_id', 'user_name', 'user_password', 'user_regdate', 'user_last_login') VALUES (1, 'admin', '43e9a4ab75570f5b', '2005-02-20 17:35:44', '2005-03-02 21:00:14');
INSERT INTO 'tbl_user' ('user_id', 'user_name', 'user_password', 'user_regdate', 'user_last_login') VALUES (3, 'webmaster', '026cf3fc6e903caf', '2005-03-02 17:52:51', '0000-00-00 00:00:00');
_____________________________________
tu n a donc pas de champs reserver a l utilistaur ou au administrateur. il te faut un test sur le login que je ne vois pas dans le code lors du log ...
il faut rajouter ce test et adapter des menus si ce n est pas deja fait.
cherche la variable de $_session generer lors du session_start();
il faut rajouter ce test et adapter des menus si ce n est pas deja fait.
cherche la variable de $_session generer lors du session_start();
dans un fichier function.php, on a le script qui gére le login:
______________________________________________________________
<?php
/*
Check if a session user id exist or not. If not set redirect
to login page. If the user session id exist and there's found
$_GET['logout'] in the query string logout the user
*/
function checkUser()
{
// if the session id is not set, redirect to login page
if (!isset($_SESSION['plaincart_user_id'])) {
header('Location: ' . WEB_ROOT . 'admin/login.php');
exit;
}
// the user want to logout
if (isset($_GET['logout'])) {
doLogout();
}
}
.....
_________________________________________
la dessus on vient bien la variable $_session
l'administrateur est un utilisateur comme les autres qui se trouve dans la table user
______________________________________________________________
<?php
/*
Check if a session user id exist or not. If not set redirect
to login page. If the user session id exist and there's found
$_GET['logout'] in the query string logout the user
*/
function checkUser()
{
// if the session id is not set, redirect to login page
if (!isset($_SESSION['plaincart_user_id'])) {
header('Location: ' . WEB_ROOT . 'admin/login.php');
exit;
}
// the user want to logout
if (isset($_GET['logout'])) {
doLogout();
}
}
.....
_________________________________________
la dessus on vient bien la variable $_session
l'administrateur est un utilisateur comme les autres qui se trouve dans la table user
Salut ...
Peut être que j'ai pas tout lu, mais c'est quoi le problème au juste, quand est ce que tu rencontre une erreur ??
Peut être que j'ai pas tout lu, mais c'est quoi le problème au juste, quand est ce que tu rencontre une erreur ??
J'ai télécharger un script qui gére un simple boutique en ligne, avec catalogue de produit. j'arrive pas a me connecter a l'interface admin.