SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation date && time && ip

    Okay I just drew up a quick form and php script. I am trying to create a little registration script.
    How would I go about getting the users ip adress and date time they registered?

    Is my securing the password good enough?

    Should I be using a mysql_real_escape_string function in places?

    HTML Code:
    <form action="registered.php">
    <input type="hidden" name="ip" value="<?php 'their ip adress??' ?>" >
    <input type="hidden" name="registered" value="<?php 'their registration date time??' ?>" >
    Email address: <input type="text" name="username" value="">
    Password: <input type="password" name="password" value="">
    Confirm Password: <input type="password" name="password2" value="">
    <input type="submit" name="submit" value="submit">
    </form>
    PHP Code:
    <?php

    if (isset['submit']) 
        {
        
    $username $_POST['username'];
        
    $password md5($_POST['password']);
        
    $ip $_POST['ip'];
        
    $registered $_POST['registered']

        
    $query 'INSERT INTO '.$db->prefix.'users (username, password, registration_date, user_ip,) VALUES('.$username.', '.$password.', '.$registered.', '.$ip); 
        
    $result mysql_query($query);
        }
    ?>

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    IP: $_SERVER['REMOTE_ADDR']
    Date: date()

    Use mysql_real_escape_string() whenever you accept user input and on all strings. Remember, this is not a replacement for data validation.

  3. #3
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What would I put between the brackets for date function?

  4. #4
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    That depends on how you want it formatted. The php documentation page I linked to will tell you what your options are.

  5. #5
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, that was easy enough thanks!

    I have something new that is much more complicated. Basically selecting all ips, and checking the last time when the viewed a certain page. Any ideas on that one?

    I am thinking maybe, create a new table for this one? or maybe just a new field in the users table called last visit and base it only on that particular page?

  6. #6
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the updated script.. does the while loop look plausible?
    I am trying to make it so that two people cannot register with the same name.

    PHP Code:
    <?php

    require 'config.php';

    $result mysql_query('SELECT * FROM users') or die('Could not gather info: ' mysql_error());


    if (isset(
    $_POST['submit'])) 
        {
        
    $username $_POST['username'];
        
    $password sha1($_POST['password']);
        
    $ip $_SERVER['REMOTE_ADDR'];
        
    $registered date("F j, Y, g:i a");  
        
        while (
    $line mysql_fetch_array($resultMYSQL_ASSOC)) 
                {
            if (
    $username != $line['username'])
            {
        
    $query 'INSERT INTO users (username, password, registration_date, user_ip) VALUES('.$username.', '.$password.', '.$registered.', '.$ip.')';
        
    $result mysql_query($query);
                }
            }
        } 
        
        else 
        {
            echo 
    'Die Hacking Attempt!';
        }

            
    ?>
    New problem

    Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'localhost, root, ' (11004) in C:\Program Files\wamp\www\tyrant\config.php on line 8

    Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\wamp\www\tyrant\config.php on line 9

    Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\Program Files\wamp\www\tyrant\config.php on line 9
    Could not select database

    PHP Code:
    <?php

    $dbname 
    'tyrant';
    $dbuser 'root';
    $dbhost 'localhost';
    $dbpass '';

        
    mysql_connect($dbhost.', '.$dbuser.', '.$dbpass);
        
    mysql_select_db($dbname) or die('Could not select database');
        
    ?>
    Fixed problem
    Last edited by t0WL337; Jun 8, 2007 at 13:59. Reason: Fixed


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •