January 27th, 2013, 12:35 PM
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
January 27th, 2013, 01:01 PM
You could use a server-side language such as PHP to do this. Would be quite easy to implement also.
January 27th, 2013, 01:08 PM
Ok, but how do i do it and use php Iv only used html
January 27th, 2013, 01:26 PM
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?
January 27th, 2013, 01:33 PM
Hi, Im runing windows xp , and I am using this for a test site but still waiting for verification form them but ya php.
January 27th, 2013, 01:54 PM
January 27th, 2013, 02:38 PM
Ok have it installed now.
January 27th, 2013, 03:15 PM
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:
Make sure when you add it that the ending PHP bracket (the ?>) has no space after it. Your doctype must come STRAIGHT after it.
$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());
$rows = $stmt->affected_rows;
if($rows == 1)
echo "Successfully inserted into database!";
echo "Error with the insert.";
For example this is wrong:
Notice how there is space between the ending php tag and the doctype. You must do it like this:
//insert to database bla bla
Notice no space.
//insert to database bla bla
Have a go, if you follow it exactly as i've said you should get on ok.
Last edited by Nanomech; January 27th, 2013 at 03:18 PM.
January 27th, 2013, 05:05 PM
do you know any good php makers like FrontPage.
January 27th, 2013, 05:37 PM
No. I write everything manually with Notepad++.
January 27th, 2013, 11:48 PM
"good" and "frontpage" should never be used in the same sentence. It's so full of security holes and bugs it's not funny.
Originally Posted by andrea825
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.
January 29th, 2013, 11:58 AM
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.