Jump to content

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">

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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