Kokowawa Posted September 28, 2007 Share Posted September 28, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/71103-need-help-with-php-code-please/ Share on other sites More sharing options...
pocobueno1388 Posted September 28, 2007 Share Posted September 28, 2007 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71103-need-help-with-php-code-please/#findComment-357562 Share on other sites More sharing options...
Kokowawa Posted September 29, 2007 Author Share Posted September 29, 2007 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"> Quote Link to comment https://forums.phpfreaks.com/topic/71103-need-help-with-php-code-please/#findComment-357812 Share on other sites More sharing options...
Cagecrawler Posted September 29, 2007 Share Posted September 29, 2007 You'll need to use mysql_connect and mysql_select_db to connect to your database. http://uk2.php.net/manual/en/ref.mysql.php Quote Link to comment https://forums.phpfreaks.com/topic/71103-need-help-with-php-code-please/#findComment-357817 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.