Jump to content

save number of views of an image on database


svgmx5

Recommended Posts

My current project requires me to save the number of views an image (banner ad) has appeared on users website. The problem here is that the image will be appearing on several users website and i want to be able to save the number of times it has appeared on my database. I know how to do this if the image was on the same server as the database, but not when the image and database are on completely different servers.

 

This is somewhat like analytic where it tracks the visitors to a page. Does anyone how i can accomplish this?

 

i figured i would need to create a JavaScript code to provide to the user so they can place it on the site but how do i get that code to connect to my database?

Link to comment
Share on other sites

You would need for the clients to access your images through a PHP script... that acts as the image src

 

For instance, you clients won't have an image path, but a path to a PHP script with query variable in it.

Let's say you have a PHP file on your server called.... advert.php

if(isset($_GET['src']) {
$imagepath=$_GET['src'];
/*
Here you could have either an index number or a filename.. whatever you have in your database.  The point is that you use what is in the $_GET['src'] variable to return an image object.
*/
$image=imagecreatefromjpeg($imagepath);

// get image height

$imgheight=imagesy($image);

//allocate color for image caption (white)

$color=imagecolorallocate($image, 255, 255, 255);

//Add text to image bottom

imagestring($image, 5, 100, $imgheight-50, "September 2005", $color);

header('Content-Type: image/jpeg');

imagejpeg($image);
}
?>

 

Then, you can give your client an img source of something like

http://mysite.com/advert.php?src=bigoleadvertisement

 

Or if you're using the index way,

http://mysite.com/advert.php?src=555

Link to comment
Share on other sites

but how could i achieve this using a javascript script?

You would still need to use PHP because JS cannot interact with the server.

 

Create a PHP page that adds one to the database column, and echos an image.  In JQuery, you would simply use the load() function to call the PHP page.  This would put the contents of that page into the container of your choice, and would run the PHP script to add the +1.

 

Little side note.  If you echo anything else on that page, it will show up when you load() the contents, so I would make sure you only put the image.

Link to comment
Share on other sites

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.