logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 10-20-2011, 03:16 AM   #1
afnan
 
Join Date: Oct 2011
Posts: 4
Exclamation admin login system

hi gues,

how are they?

I wanna go to create PHP admin login system,

index.php
PHP Code:
<?php
session_start
();
if(!isset(
$_SESSION["mangre"])){
    
header("location:admin_login.php");
    exit();
}
//this manger session value is in fact in the database
$managerID preg_replace('#[^0-9]#i','',$_SESSION["id"]);
$manager preg_replace('#[^A-Za-z0-9]#i','',$_SESSION["manager"]);
$password preg_replace('#[^A-Za-z0-9]#i','',$_SESSION["password"]);

include 
"../storescripts/connect_to_mysql.php";
$sql mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1");
$existCount mysql_num_rows($sql);
if (
$existCount == 0){
echo
"Your login session is not on record in the database";
exit();
}
?>

<!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>homeadmin</title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainwrraper">
<?php include_once("../template_header.php");?>
<div id="content"> admin store

<h1>Every thing Will be Good at the end </h1> </div>
<?php include_once("../template_footer.php");?>
</div>
</body>
</html>
admin_login.php
PHP Code:
<?php
session_start
();
if(!isset(
$_SESSION["managre"])){
    
header("location:index.php");
    exit();
}
?>
<?php
//Parse the log in form if the user has filled it out and pressed "Log in"
if(isset($_POST["username"])&&isset($_POST["password"])) {
   
    
$manager preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]); //Filter everything but numbers and letters
      
$password preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]); //Filter everything but numbers and letters
    //Connect to the MySQL Database
    
include"../storescripts/connect_to_mysql.php";
    
$sql=mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password'LIMIT 1");//query the person
    
$existCount mysql_num_rows($sql); //count the row numbers
    
if ($existCount == 1){ //evaluate the count
    
while ($row mysql_fetch_array($sql)) {
        
$id $row["id"];
    }
    
$_SESSION["id"] = $id;
    
$_SESSION["manager"] = $manager;
    
$_SESSION["password"] = $password;
    
header("location:index.php");
    exit();
    } else{
        echo
'there is a wrong, try again';
        }
        }
?>
<!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>homeadmin</title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainwrraper">
<?php include_once("../template_header.php");?>
<div id="content"> 
  <p>admin store </p>
  <form id="form1" name="form1" method="post" action="admin_login.php">
    <p>
      <label for="username">username</label>
      <input type="text" name="username" id="username" />
    </p>
    <p>
      <label for="password">password</label>
      <input type="text" name="password" id="password" />
      <p>
        <input type="submit" value="Submit" />
    </form>
  <p>&nbsp;</p>
</div>
<?php include_once("../template_footer.php");?>
</div>
</body>
</html>
but when I open admin_login.php in firefox , and enter username and password , it not go index.php

I don't know what's the problem !!

all the fill in the same folder.

help me please
afnan is offline   Reply With Quote
Old 10-20-2011, 07:35 AM   #2
Corrosive
Corrosive's Avatar
 
Join Date: Feb 2008
Location: Bristol, England
Posts: 7,103
Default

Typo;

Code:
session_start();
if(!isset($_SESSION["managre"])){
    header("location:index.php");
    exit();
}
The session is called 'manager'.
Corrosive is offline   Reply With Quote
Old 10-20-2011, 05:49 PM   #3
afnan
 
Join Date: Oct 2011
Posts: 4
Default

so, where is the mistake !!!
afnan is offline   Reply With Quote
Old 10-20-2011, 05:52 PM   #4
Corrosive
Corrosive's Avatar
 
Join Date: Feb 2008
Location: Bristol, England
Posts: 7,103
Default

In the code I posted above.
Corrosive is offline   Reply With Quote
Old 10-20-2011, 05:57 PM   #5
afnan
 
Join Date: Oct 2011
Posts: 4
Default

index.php
PHP Code:
session_start();
if(!isset(
$_SESSION["mangre"])){
    
header("location:admin_login.php");
    exit();

admin_login.php

PHP Code:
session_start();
if(!isset(
$_SESSION["managre"])){
    
header("location:index.php");
    exit();

your answer

PHP Code:
session_start();
if(!isset(
$_SESSION["managre"])){
    
header("location:index.php");
    exit();

tell me exatly, where is the mistake.

I don't see any differane between my code and your code
afnan is offline   Reply With Quote
Old 10-20-2011, 06:07 PM   #6
Corrosive
Corrosive's Avatar
 
Join Date: Feb 2008
Location: Bristol, England
Posts: 7,103
Default

I didn't update the code for you I just pointed out that 'manager' was spelt incorrectly. I even made the typo bold so you'd see it.
Corrosive is offline   Reply With Quote
Old 10-20-2011, 06:27 PM   #7
afnan
 
Join Date: Oct 2011
Posts: 4
Default

ok.
now, "manager" is correct.

index.php
PHP Code:
<?php
session_start
();
if(!isset(
$_SESSION["manager"])){
    
header("location:admin_login.php");
    exit();
}
//this manger session value is in fact in the database
$managerID preg_replace('#[^0-9]#i','',$_SESSION["id"]);
$manager preg_replace('#[^A-Za-z0-9]#i','',$_SESSION["manager"]);
$password preg_replace('#[^A-Za-z0-9]#i','',$_SESSION["password"]);

include 
"../storescripts/connect_to_mysql.php";
$sql mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1");
$existCount mysql_num_rows($sql);
if (
$existCount == 0){
echo
"Your login session is not on record in the database";
exit();
}
?>
admin_login.php
PHP Code:
<?php
session_start
();
if(!isset(
$_SESSION["manager"])){
    
header("location:index.php");
    exit();
}
?>
<?php
//Parse the log in form if the user has filled it out and pressed "Log in"
if(isset($_POST["username"])&&isset($_POST["password"])) {
   
    
$manager preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]); //Filter everything but numbers and letters
      
$password preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]); //Filter everything but numbers and letters
    //Connect to the MySQL Database
    
include"../storescripts/connect_to_mysql.php";
    
$sql=mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password'LIMIT 1");//query the person
    
$existCount mysql_num_rows($sql); //count the row numbers
    
if ($existCount == 1){ //evaluate the count
    
while ($row mysql_fetch_array($sql)) {
        
$id $row["id"];
    }
    
$_SESSION["id"] = $id;
    
$_SESSION["manager"] = $manager;
    
$_SESSION["password"] = $password;
    
header("location:index.php");
    exit();
    } else{
        echo
'there is a wrong, try again';
        }
        }
?>
if I'm open admin_login.php, see what happen




then, when I press Submit ,



, I want open index.php when I press submit button


help me please
afnan is offline   Reply With Quote
Old 10-21-2011, 02:14 AM   #8
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,170
Default

did you write this script?
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 10-27-2011, 02:58 PM   #9
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

@ed I dont think so!

Where is your form action pointing?
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:28 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com