Jump to content

INeedAGig

Members
  • Posts

    112
  • Joined

  • Last visited

    Never

Posts posted by INeedAGig

  1. Hey guys. I was wondering how I would go about echoing the last logged in user with time/date when I log into my database?

     

    For example, I already have it echoing your username when you log in, i.e. "Welcome Username, Logout" but I would like to echo the prior logged in username with the time and date they logged in on a different line.

  2. Ok, the database I have been working on the past few days is located on my websites server (1&1) and today I am trying to get a connection to it on a website that is on a different server, but I am getting my echo statement of saying it can't find the database even though I changed it from "localhost" to the physical address of the database.  Any ideas?

  3. What are you using to write your code? I just solved the same issue in one of my scripts. It was caused by a BOM (Byte Order Mark) which is an invisible line of code before the initial <?php. PHP will know it's there and process it, which will cause header errors.

  4. Okay, I tried your suggestion and changed the code to

     

    <?php
    session_start();
    session_destroy();
    header ("location: login.php");
    session_close();
    ?>
    

     

    This results in the following error:

     

    Fatal error: Call to undefined function: session_close() in logout.php on line 5

     

  5. Hey guys, me again. A few of you were helping me with my login script, which I did finally get working. I am having one small problem though. Upon clicking the logout link, it does not re-direct back to the login page, it just stays blank. I have pasted my code from my logout.php file for reference. Thanks in advance for your help! :)

     

    Logout.php code

    <?php
    session_start();
    session_destroy(); {
    header("location: login.php");
    }
    exit();
    ?>
    

  6. Hey guys, minor issue I can't seem to resolve, I have tried a couple things but am still getting this error.

     

    The error is:

    Parse error: syntax error, unexpected T_STRING in login.php on line 17

     

     

     

    Here is the code from the page:

     

    <?php
    //Database Information
    $dbhost = "removed_for_this_post"; //Host Name
    $dbname = "removed_for_this_post"; //Database Name
    $dbuser = "removed_for_this_post"; //Database Username
    $dbpass = "removed_for_this_post"; //Database Password
    
    //Connect To Database
    mysql_connect($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    
    session_start();
    
    $username = $_POST[‘username’];
    $password = md5($_POST[‘password’]);
    
    $query = “SELECT * FROM users WHERE username='$username' AND password='$password'”; 
    $result = mysql_query($query);
    
    if (mysql_num_rows($result) != 1) {
    $error = “Bad Login”;
    include “login.html”;
    } else {
    $_SESSION[‘username’] = “$username”;
    include “mypd_interface.php”;
    }
    
    ?>
    

     

    Thanks in advance!  8)

  7. LOL, you are back at the point of needing to read and follow the first two replies in the last thread you started for this code -

     

    Your header() redirect is probably failing due to your script outputting some blank lines at the start of your file before the <?php tag.

     

    Are you developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed? You will save a TON of time.

     

    Also, session_register() was depreciated almost 9 years ago and won't work on a majority of php installations today and is going to be removed in the next major php version release.

     

    You should be setting and referencing $_SESSION variables and you will need a session_start() statement in your code before you output anything to the browser.

     

    You need to put the error_reporting() statement after the line with the first <?php tag and before any other code so that you will see ALL the errors.

     

     

    I've done all that :)  Hehe, and it was my mistake with the session_register() this time, I just modified a previous file I had saved and forgot to remove it....again...lol. But, I reviewed everything from my last post and am only down to that one error. I have verified that there is nothing being processed before the initial <?php tag

  8. Okay, a few of you have been helping me with a login script problem. I have changed it quite a bit again, but I am still running into a little bit of a problem.

     

    When I click the submit button it just clears the form fields and stays on the login page. Also, I have used error_reporting(E_ALL) to help me out with debugging. I took care of three bugs on my own but I cant seem to clear the two remaining bugs and the fact that it is not forwarding me to any page with my header statement. 

     

    Thanks for your help in advance! :)

     

    Here is my code from my 'login.php' file.

     

    <?php
    session_start();
    error_reporting (E_ALL);
    include("config.php");
    if($_SERVER["REQUEST_METHOD"] == "POST")
    {
    // username and password sent from form 
    $myusername=addslashes($_POST['username']); 
    $mypassword=addslashes($_POST['password']); 
    
    $sql="SELECT id FROM admin WHERE username='$myusername' and passcode='$mypassword'";
    $result=mysql_query($sql);
    $row=mysql_fetch_array($result);
    $active=$row['active'];
    $count=mysql_num_rows($result);
    
    
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1)
    {
    session_register("myusername");
    $_SESSION['login_user']=$myusername;
    header("location: main_interface.php");
    }
    else 
    {
    $error="The username or password you entered is invalid, please check your credentials and try again";
    }
    }
    ?>
    <form action="" method="post">
    <label>Username :</label>
    <input type="text" name="username"/><br />
    <label>Password :</label>
    <input type="password" name="password"/><br/>
    <input type="submit" value=" Submit "/><br />
    </form>
    

     

    Here are the error messages on the page

     

    Notice: Undefined index: active in login.php on line 20

     

    Warning: Cannot modify header information - headers already sent by (output started at login.php:1) in login.php on line 29

     

     

     

    Thanks in advance for your help! :)

     

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.