#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    Question Hi I had this code and now i lost it


    Hi I had this code and now i lost it, Im looking for html code that when someone gose on my website i get there ip address and it saves to a database, how can i get this agine thanks for your time
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    300
    Rep Power
    9
    You could use a server-side language such as PHP to do this. Would be quite easy to implement also.

    Regards,

    NM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    Ok, but how do i do it and use php Iv only used html
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    300
    Rep Power
    9
    Are you using a host to host your website? If so you can work with files on your server.

    If not, i'd install a program called WAMP(for Windows users), MAMP(for Mac users), LAMP(for linux user) and there is one called XAMPP which I've never read about.

    I don't mind writing it for you but obviously you're going to want somewhere to test it and you will need either a host or a local server (WAMP) to test the PHP and MySQL operations.

    What OS are you running?

    Kind regards,

    NM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    Hi, Im runing windows xp , and I am using this for a test site but still waiting for verification form them but ya php.
    programmingandhacking.netai.net
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    300
    Rep Power
    9
    Download WAMP here: http://www.wampserver.com/en/

    Regards,

    NM.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    Ok have it installed now.
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    300
    Rep Power
    9
    Ok that's great.

    First we should really create a database.

    When you run WAMP, click the icon in the taskbar and go to phpMyAdmin.

    When that loads up, click on the 'Databases' tab in the top menu. When the page loads, enter a name for your database and click create. Call it something like user_info.

    Ok, now we have our database but we need a table to hold the information. When the database is created, you get taken to a new page, find the 'Create Table' input field and enter a name for your table. Something descriptive like 'user_ips' in the 'Number of Columns' field, let's enter just the minimum required for now which is 2 and click the 'Go' button.

    phpMyAdmin will now bring up a 'form' type box. In the name field for the first field, enter 'id' as the name. Leave it as an 'INT' type. In the 'Length/Values' column type something like 10.

    Go over to the right - click the drop down list in under the 'Index' column and select 'PRIMARY'. Then the last thing to do is make sure you tick the 'A-I' (Auto-Increment) checkbox.

    Go to your next field - for the name type in 'ip_addresses'. Change the type to a varchar and give it a length/value of say 30 to be covered.

    Now click the 'Save' button and your set to go.

    Now, create your HTML page but save it as a .php file and NOT .html.

    Still add your doctype, head,body etc tags just as you would normally with a basic HTML file.

    In the top of the page, even BEFORE the <!DOCTYPE> declaration, add this:
    PHP Code:
    <?php

    $user_ip 
    $_SERVER['REMOTE_ADDR'];

    $conn = new mysqli("localhost","root","","user_ips") or die(mysqli_error());

    $stmt $conn->prepare("INSERT INTO user_info (ip_addresses) VALUES (?)") or die(mysqli_error());
    $stmt->bind_param("s",$user_ip);
    $stmt->execute();
    $stmt->store_result();

    $rows $stmt->affected_rows;

    if(
    $rows == 1)
    {
        echo 
    "Successfully inserted into database!";
    }
    else
    {
        echo 
    "Error with the insert.";
    }

    ?>
    Make sure when you add it that the ending PHP bracket (the ?>) has no space after it. Your doctype must come STRAIGHT after it.

    For example this is wrong:
    PHP Code:
    <?php
    //insert to database bla bla
    ?>

    <!DOCTYPE>
    Notice how there is space between the ending php tag and the doctype. You must do it like this:

    PHP Code:
    <?php
    //insert to database bla bla
    ?>
    <!DOCTYPE>
    Notice no space.

    Have a go, if you follow it exactly as i've said you should get on ok.

    Good luck

    Kind regards,

    NM.
    Last edited by Nanomech; January 27th, 2013 at 04:18 PM.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    do you know any good php makers like FrontPage.
  18. #10
  19. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    300
    Rep Power
    9
    No. I write everything manually with Notepad++.

    Regards,

    NM.
  20. #11
  21. Known to taste like chicken
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    In front of my computer
    Posts
    399
    Rep Power
    312
    Originally Posted by andrea825
    do you know any good php makers like FrontPage.
    "good" and "frontpage" should never be used in the same sentence. It's so full of security holes and bugs it's not funny.

    Long story short no, there are no "php makers" out there. The closest thing would be a 'CMS' like Drupal. CMSs tend to have a lot of overheads (and potential security issues of their own, although there are usually decent security patches coming out fairly regularly), so for a simple website I would highly recommend just writing the code yourself. Like Nanomech said, notepad++ is the way to go on windows.
    "Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

    Looking for a project Idea?
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,031
    Rep Power
    377
    and this is 2012. Frontpage still exists? Dreamweaver, I would say is better.

    PHP code cannot be written by dreamweaver/frontpage. You can google for script put that into your page.

IMN logo majestic logo threadwatch logo seochat tools logo