Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Login script help

    I am making a pay-for-use site that I am having trouble with the login. I have made a few sites before with login pages using Dreamweaver, but this one requires a bit of PHP code. Apparently that is a weak point since I have only read a few books on PHP.

    The site will have access for 6 or 12 months. I have a MySQL DB that captures the name, address, etc. It also captures two DATE fields. One for the registration date, reg_date. The other DATE field is for expiration date, expiry_date. For example, if a user registers for 12 months on March 1, the reg_date field is populated with 2007-03-01 and the expiry_date is filled with 2008-03-01.

    I would like the login to check these two date fields to grant access to certain pages. I think a little math should do the trick, but am not sure how to do it. BTW- if there is a better way, I am willing to scrap this method and try something else.

    I have a small test page produced in DW that I can attach the code here if needed. It uses the DW behaviors to allow access based on a privilege level. I am really a PHP noob and will appreciate any help that is given.

  • #2
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    If you are using MySQL 4.1.1 or higher simply pass the DATEDIFF() in a sql statement. If you are using an older version you can use the DATE_SUB().

    PHP Code:
    //This will get all the logins that are OLDER than a year.
    $sql "SELECT * FROM table_name WHERE DATEDIFF(now(), reg_date) >= 365"// > MySQL 4.1.0

    //This will get all the logins that are OLDER than a year.
    $sql "SELECT *, DATE_FORMAT(reg_date,'%m-%d-%Y') AS theDate FROM table_name WHERE DATE_SUB(CURDATE(),INTERVAL 1 YEAR) >= reg_date;";  // < MySQL 4.1.0 syntax
    $q mysql_query($sql);

    $i 0;
    while (
    $r mysql_fetch_assoc($q)) {
        
    $i++;
        echo 
    "Record Number" $i;
        echo 
    "Registration Date: ";
        echo 
    $r[reg_date];
        echo 
    " - ";
        echo 
    $r[theDate];  //formats the date: 3-07-2007
        
    echo "<br />";

    You can use MONTH as an INTERVAL in the second version: INTERVAL 6 MONTH
    Last edited by StupidRalph; 03-07-2007 at 06:29 PM. Reason: forgot a quotation mark...
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #3
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I checked my hosting company, which is 1and1.
    phpinfo shows MySQL version 5.0.18
    but SELECT_VERSION shows that they are actually using 4.0.27
    so, I guess I should use the second one listed, correct?

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Yeah, it should be the one that MySQL reported.

  • #5
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Its funny you say that...I just built a site using 1and1 servers using similar code.....if you are using their servers on perfora.net...then they are 4.0.27 which is soooooooooo out dated...Let me know if you need help. I think you MIGHT need to set the connection and use MYSQL_CLIENT_IGNORE_SPACE so that you can use MYSQL functions..I'm not sure...just use that second query I supplied you with and you'll be okay...
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

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