Jump to content

Need help with PHP-code, please!


Kokowawa

Recommended Posts

Hello there,

 

I have a PHP-based webpage using MySql. I want to store the IP-adresses of the visitors into DB and when it's a new visitor (ip) the start page will show an extra image (or pop up) that will never be shown again for the same IP.

 

Please help me, I've got the idea but not the code.

Link to comment
https://forums.phpfreaks.com/topic/71103-need-help-with-php-code-please/
Share on other sites

Well...first you need to check your database if that IP exists yet, and if it doesn't add it and show the image.

 

<?php

$ip = $_SERVER['REMOTE_ADDR'];
$query = "SELECT col FROM ips WHERE ip='$ip'";
$result = mysql_query($query)or die(mysql_error());

if (mysql_num_rows($result) < 1){
   //add IP to database
  //display image
}

?>

Hi, thanks for your help.

 

I tried here http://cityline.se/test1.php to fix it but I don't know what seems to be wrong. Maybe it's not connected to the DB. How can I fix it?

 

This is the code for test1.php

 

<?php

$ip = $_SERVER['REMOTE_ADDR'];
$query = "SELECT col FROM ips WHERE ip='$ip'";
$result = mysql_query($query)or die(mysql_error());

if (mysql_num_rows($result) < 1){
include( 'innehall.php' ); 
}

?>

 

This is the code for innehall.php

 

<img src="http://www.google.se/intl/en_com/images/logo_plain.png">

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.