1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Trying to create a global file to call all information

Discussion in 'PHP' started by HellBomb, Sep 11, 2010.

  1. HellBomb

    HellBomb Active Member

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    80
    #21
    Ok I am getting a whole slew of errors, I am assuming that I am just doing this wrong, care to double check...

    <?php
    
    	// starts a session. The session has to be started at
    	// the begeining of the program, even though the user
    	// hasn't logged in yet.
     session_start();
    	
    	// This will check if the user is already logged in
    	// if the user is logged in then it will redirect that
    	// user to the Administrative Control Panel.
     if (@$_SESSION['auth'] == "yes")
    	{
    		header("Location: index.php");
    		exit();
    	}
     
     	$_SESSION['username'] = $_POST['user'];
    	$_SESSION['password'] = $md5pass;
    	  	if(isset($_POST['remember'])){
        		setcookie("cookname", $_SESSION['fusername'], time()+60*60*24*100, "/");
        		setcookie("cookpass", $_SESSION['fpassword'], time()+60*60*24*100, "/");
      		 }
    			 
     	// Reads in the file that sets the variables needed to
    	// connect to the database. The program is called 
    	// global.php, which is a the core of the program.
    	// Global.php the file that connects all the
    	// information from various script into one file so
    	// you only have to call a single file instead of
    	// several different files to do common tasks.
     include("../global.php");
     	
    	// starts a switch statement. The Switch statement
    	// contains two sections, based on the value for the
    	// hidden variable $do in the form, obtained from the 
    	// built-in array $_POST. The first section runes when
    	// the value passed for the do is login; the second
    	// section runs when the value passed is new; and the 
    	// third section is the default that runs if no value
    	// is passed for do. The third section just displays
    	// the login page and runs only when the customer
    	// first links to the login page.
     switch (@$_POST['do'])
     {
    	// starts the case block for the login section - the 
    	// section that runs when the customer logs in. The 
    	// login section of the form sends the hidden variable
    	// $do with the balue login, which causes this section
    	// of the switch statement to run.
       case "login":
       
    	// Lines 45-49 look in the database table "staff"
    	// for a row with the login name typed in by the user.
         $sql = "SELECT loginName FROM staff
                 WHERE loginName='$_POST[fusername]'";
         $result = mysqli_query($cxn,$sql)
                   or die("Couldn't execute query.");
    			   
    	// Starts an if block that executes if the member ID
    	// was found. This means tha user submitted Member
    	// ID that is in the database. This block then checks
    	// to see whether the password submitted by the user
    	// is correct for the given Member IF. This block is
    	// documented in more detail in the following
    	// comments.
         $num = mysqli_num_rows($result);
         if ($num > 0)  // login name was found
         {
    		 
    	// The following lines create a query the looks for a 
    	// row with both the Member ID and the password
    	// submitted by the customer. Notice that the password
    	// submitted in the form ($fpassword) is encrypted by
    	// using the MySQL function md5(). Passwords in the
    	// database are encrypted, so the password you are
    	// trying to match must also be encrypted, or it wont
    	// match.
            $sql = "SELECT loginName FROM staff 
                    WHERE loginName='$_POST[fusername]'
                    AND password=md5('$_POST[fpassword]')";
    				
    	// THe following lines execute the query and chech 
    	// whether a match was found. $num2 equals 1 or 0,
    	// depending on whether a row with both the Member
    	// ID and the password is found.
            $result2 = mysqli_query($cxn,$sql)
                       or die("Couldn't execute query 2.");
            $num2 = mysqli_num_rows($result2);
    		
    	// Starts an if block that executes if the password is
    	// correct. This is a successful login. Lines 88-96
    	// are executed, performing the following tasks: 1)
    	// the two session variables, auth and logname, are
    	// stored in the SESSION array. 2) $today is created
    	// with today's date and time in the correct format
    	// expected by the database table. 3) A row for the 
    	// is entered into the Login table. 4) The first page
    	// of the Staff Section is sent to the user.
            if ($num2 > 0)  // password is correct
            {
               $_SESSION['auth']="yes";
               $logname=$_POST['fusername']; 
               $_SESSION['logname'] = $logname;
               $today = date("Y-m-d h:i:s");
               $sql = "INSERT INTO login (loginName,loginTime,loginIP)
                       VALUES ('$logname','$today','".$_SERVER['REMOTE_ADDR']."')";
               $result = mysqli_query($cxn,$sql) 
                         or die("Can't execute insert query.");
               header("Location: index.php");
            }
    
    	// Starts an else block that execures if the password
    	// is not correct. This is an unsuccessful login.
    	// Lines 121-124 are executed, performing the following
    	// tasks: 1) The appropriate error message is set in
    	// $message. 2) The login page is displayed again. The
    	// login page will show the error message. Notice that
    	// the block starting on line 42 lets the user know
    	// when he or shy has a real login name but the wrong
    	// password. If the security of your data is
    	// important, you may want to write this loop
    	// differently. Providing that the information may
    	// be helpful to someone who is trying to break in
    	// because now the cracker needs to only find the 
    	// password. For more security, just have the one 
    	// condition that gives the same error message
    	// whenever either the login name of the password
    	// is incorrect. In this example, I prefer to
    	// provide the information because it is helpful
    	// to the legitimate member (who may not remember
    	// whether he or she installed the accounta t all),
    	// and I'm not protecting any vital information.
            else    // password is not correct
            {
               $message="The Login Name, '$_POST[fusername]'
                         exists, but you have not entered the
                         correct password! Please try again.<br>";
               include("test.php");
            }
    		
    	 // Ends the block that executes when the Member ID
    	 // is found in the database.
         }
    	 
    	// Starts an if block that executes when the Member ID
    	// is NOT found in the database. This could actually 
    	// be and ELSE, instread of an elseif but I think it's
    	// clearer to humens with the if condition in the
    	// statement. This block creates the appropriate error
    	// message and shows the login page again, which 
    	// includes the error message.
         elseif ($num == 0)  // login name not found
         {   
            $message = "The Login Name you entered does not 
                        exist! Please try again.<br>";
            include("test.php"); // This is the login page
         }
    	 
    	// Ends teh case block that executes when the user
    	// submits a Member ID and password to log in. The
    	// login block extends from line 34 to line 145.
       break;
    
    	// Starts the CASE block for the condition. If $do is 
    	// not set to either "login" or "new", the program
    	// skips to this block. Because both forms on the login
    	// page send $do, this block executes only the first
    	// time this program runs - when the user links to it
    	// from the storefront page and has not yet submitted 
    	// either form. This section has only one statement:
    	// a statement that displays the login page.
        default:
            include("test.php");
      }
    ?>
    
    PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Simpla Admin | Sign In</title>
    <link rel="stylesheet" href="resources/css/reset.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="resources/css/style.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="resources/css/invalid.css" type="text/css" media="screen" />	
    <script type="text/javascript" src="resources/scripts/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="resources/scripts/simpla.jquery.configuration.js"></script>
    <script type="text/javascript" src="resources/scripts/facebox.js"></script>
    <script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>
    </head>
    	<body id="login">
    		
    		<div id="login-wrapper" class="png_bg">
    			<div id="login-top">
    			
    				<h1>Simpla Admin</h1>
    				<!-- Logo (221px width) -->
    				<img id="logo" src="resources/images/logo.png" alt="Simpla Admin logo" />
    			</div> <!-- End #logn-top -->
    			
    			<div id="login-content">
    				
    				<form action="login.php" method="POST">
    				
    					<div class="notification information png_bg">
    						<div>
    							This is for Staff members only.
    						</div>
    					</div>
    					
    					<p>
    						<label>Username</label>
    						<input name="fusername" class="text-input" type="text" value="<?php echo "$cookname;" ?>" />
    					</p>
    					<div class="clear"></div>
    					<p>
    						<label>Password</label>
    						<input name="fpassword" class="text-input" type="password" value="<?php echo "$cookpass;" ?>" />
    					</p>
    					<div class="clear"></div>
    					<p id="remember-password">
    						<input name="remember" type="checkbox" />Remember me
    					</p>
    					<div class="clear"></div>
    					<p>
    						<input type="hidden" name="do" value="login" />
    						<input name="log" class="button" type="submit" value="Sign In" />
    					</p>
    					<div class="clear"></div>
    					<?php
    						if (isset($message))
    							{
    					echo "<div class='notification information png_bg'>
    						<div>
    							$message
    						</div>
    					</div>";		
    							}
    					?>
    				</form>
    			</div> <!-- End #login-content -->
    			
    		</div> <!-- End #login-wrapper -->
      </body>
    </html>
    
    PHP:

     
    HellBomb, Sep 13, 2010 IP
  2. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #22
    change the index page areas to this

    <p>
    <label>Username</label>
    <input name="fusername" class="text-input" type="text" value="<?php echo $_GET['cookname']; ?>" />
    </p>
    <div class="clear"></div>
    <p>
    <label>Password</label>
    <input name="fpassword" class="text-input" type="password" value="<?php echo $_GET['cookpass']; ?>" />
    </p>
    <div class="clear"></div>
    <p id="remember-password">
    <input name="remember" type="checkbox" />Remember me
    </p>
     
    lowridertj, Sep 13, 2010 IP
  3. HellBomb

    HellBomb Active Member

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    80
    #23
    it is as follows

    Notice: undefined index: user in C:\wamp\www\fcs\admin\login.php on line 17
    Notice: Undefined variable:md5pass in C:\wamp\www\fcs\admin\login.php


    then at the bottom,
    Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

    I am using php 5.3.0
     
    HellBomb, Sep 13, 2010 IP
  4. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #24
    in the top of the globals file put this there

    
    <?php
    // Emulate register_globals on
    if (!ini_get('register_globals')) {
    $superglobals = array($_SERVER, $_ENV,
    $_FILES, $_COOKIE, $_POST, $_GET);
    if (isset($_SESSION)) {
    array_unshift($superglobals, $_SESSION);
    }
    foreach ($superglobals as $superglobal) {
    extract($superglobal, EXTR_SKIP);
    }
    ini_set('register_globals', true);
    }
    ?>
    PHP:
    It is a way to emulate register globals as on in php 5+

    as for the login page do this at the top

    <?php
    if($_GET['cookname']){
    $cookname = $_GET['cookname'];
    }else{
    $cookname = '';
    }
    if($_GET['cookpass']){
    $cookpass = $_GET['cookpass'];
    }else{
    $cookpass = '';
    }
    ?>
    PHP:
    Then for the form area where it reads value
    change it back to
    
    <p>
    <label>Username</label>
    <input name="fusername" class="text-input" type="text" value="<?php echo $cookname; ?>" />
    </p>
    <div class="clear"></div>
    <p>
    <label>Password</label>
    <input name="fpassword" class="text-input" type="password" value="<?php echo $cookpass; ?>" />
    </p>
    <div class="clear"></div>
    <p id="remember-password">
    <input name="remember" type="checkbox" />Remember me
    </p>
    
    HTML:
     
    lowridertj, Sep 13, 2010 IP
  5. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #25
    When looking up tutorials make sure you are search latest php v5

    otherwise you will have to make adjustments for the newer version and the way it performs.
     
    lowridertj, Sep 13, 2010 IP
  6. HellBomb

    HellBomb Active Member

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    80
    #26
    Yea I was using php any mysql for dummies and just realized it was released about 4 years ago, any ideas for better new books?
     
    HellBomb, Sep 13, 2010 IP
  7. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #27
    lowridertj, Sep 13, 2010 IP
  8. HellBomb

    HellBomb Active Member

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    80
    #28
    HellBomb, Sep 13, 2010 IP
  9. HellBomb

    HellBomb Active Member

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    80
    #29
    Ugh, I these stupid errors never end! lol
    Here are my errors
    Notice: Undefined index: cookname in C:\wamp\www\fcs\admin\login.php on line 12
    Notice: Undefined index: cookpass in C:\wamp\www\fcs\admin\login.php on line 17

    	if($_GET['cookname']){ // line 12
    		$cookname = $_GET['cookname']; // line 13
    	}else{ // line 14
    		$cookname = ''; // line 15
    	} // line 16
    	if($_GET['cookpass']){ // line 17
    		$cookpass = $_GET['cookpass']; // line 18
    	}else{ // line 19
    		$cookpass = ''; // line 20
    	} // line 21
    PHP:
     
    HellBomb, Sep 13, 2010 IP
  10. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #30
    <?php
    if(isset($_GET['cookname'])){ // line 12
            $cookname = $_GET['cookname']; // line 13
        }else{ // line 14
            $cookname = ''; // line 15
        } // line 16
        if(isset($_GET['cookpass'])){ // line 17
            $cookpass = $_GET['cookpass']; // line 18
        }else{ // line 19
            $cookpass = ''; // line 20
        } // line 21
    
    ?>
    PHP:
    try this.
     
    lowridertj, Sep 13, 2010 IP
  11. HellBomb

    HellBomb Active Member

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    80
    #31
    Yep, thank you worked like a charm :) I am hoping to learn how to display like many pages from a single file, like each page will have a ?do=whatever but I want to be able to create it from the backend. So in the control panel I am building i click add page, then have 2 fields, one for adding my own custom ?do=whateveriwant and the next field will be the html of the page. I will be planning on using .htaccess rewrite later on the make much nicer links but anyways, what should i start focusing on to start building up to making something like that? Any specific topics i should be specifically learning about? or is it gonna be insanely hard and gonna have to struggle my way through it all.
     
    HellBomb, Sep 13, 2010 IP
  12. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #32
    you could end up doing things like this
    <?php
    
    include('header.php');
    
    if($example_one){
    include('page_one.php');
    }
    
    if($example_two){
    include('page_two.php');
    }
    
    if($example_three){
    include('page_three.php');
    }
    
    if($example_four){
    include('page_four.php');
    }
     
    
    include('footer.php');
    
    ?>
    PHP:
    Where the calling for if(example_one) this will be the ?example_one

    This would all go in the index page, or can make them functions.
    http://www.tizag.com/phpT/phpfunctions.php

    lots of great php tutorials here
    http://www.tizag.com/phpT/
     
    lowridertj, Sep 14, 2010 IP
  13. HellBomb

    HellBomb Active Member

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    80
    #33
    I figured their would be a mysql way of doing it. when you add the page it adds it to the mysql, when the file is linked to it checks which thing is being called then gets the content from the database.
     
    HellBomb, Sep 14, 2010 IP