Click to See Complete Forum and Search --> : Remote access to php script


tataencu
06-22-2007, 03:18 PM
I need to build a banner display tracking system. So every time a banner is displayed, it executes an php script that updates a sql database with the session details, like the address where the banner is displayed and the date and time.

I now have two questions:
1. Which is the variable for the address where the banner is displayed?
2. How do I run a script that's hosted remotely, taking into consideration that it has to reveice as an argument the banner ID, and that it contains sensitive data about the database, so it cannot be included in the banner itself, but it has to be hosted on my server?

I really appreciate any help I can get.

Sheldon
06-22-2007, 11:14 PM
Well the answer to number one depends on how you write the script.

Number two, ? are you not writing this for your own site? why does it have to be remotely hosted? but you can just include() it from the site displaying the add.


EDIT: Do you want to count clicks also?

tataencu
06-23-2007, 03:51 AM
it is for my banners that link to my site and are displayed on other sites where i advertise, so i cannot host it there.
But I still don't have any idea about no.1. So how do I do that? :)

Sheldon
06-24-2007, 01:29 AM
do you have mysql access?

Sheldon
06-24-2007, 02:47 AM
try this
it uses PHP and mySQL and you can host it yourself then just include the script on the other sites.

Comes with a script to install and add some dummy entries

<?php
// Banner advert script. one random image with working link ( and counting clicks )

mysql_connect ('localhost', '**username**', '**password**') or die (error("Unable to connect to Database Server. "));

mysql_select_db ('inboxdesign') or die (error("Could not select database. "));

function error($msg){
return $msg . mysql_error();
// You can change the return of this output after development. RG
// return $msg;
}

// This displays the advert.
if(isset($_GET['display'])){
$sql = "SELECT * FROM advertising ORDER BY rand() LIMIT 1";
$qry = mysql_query($sql) or die (error("Can not place advertisement. "));
$row = mysql_fetch_assoc($qry) or die (error("Can not place advertisement. "));
echo("<a href=\"http://www.hostofthisscript.com/path/to/thispage.php?advert={$row['id']}\"><img src=\"/images/adverts/{$row['image']}\" alt=\"{$row['company']}\" /></a>");
$display = ($row['display'] + 1);
mysql_query("UPDATE advertising SET display = '{$display}' WHERE id = '{$row['id']}'") or die (error("Cant update Display Count. "));
}

if(!empty($_GET['tracker']) and is_numeric($_GET['tracker'])){
$id = $_GET['tracker'];
$sql = "SELECT click,url FROM advertising WHERE id = '{$id}'";
$qry = mysql_query($sql) or die (error("Can not redirect link. "));
$row = mysql_fetech_assoc($qry) or die (error("Can not redirect link. "));
$click = ($row['click'] + 1);
mysql_query("UPDATE advertising SET click = '{$click}' WHERE id = '{$id}'") or die (error("Cant update Click Count. "));
header("Location: {$row['url']}");
}


/*
AFTER YOU HAVE SET UP YOUR TABLE DELETE FROM HERE ON.
*/
if(isset($_GET['create'])){
mysql_query("CREATE TABLE advertising (id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
image VARCHAR(60),
company VARCHAR(60),
url VARCHAR(60),
display INT(10),
click INT(10))") or die (error("Can not create Database"));
echo("Table Created");
}

if(isset($_GET['insert'])){
$sql = "INSERT INTO advertising (`id`,`image`,`company`,`url`,`display`,`click`) VALUES ('{$i}','image.gif','Company Name','http://www.domain.com',0,0)";
mysql_query($sql) or die (error("Can not insert dummy content. "));
mysql_query($sql) or die (error("Can not insert dummy content. "));
mysql_query($sql) or die (error("Can not insert dummy content. "));
mysql_query($sql) or die (error("Can not insert dummy content. "));
mysql_query($sql) or die (error("Can not insert dummy content. "));
mysql_query($sql) or die (error("Can not insert dummy content. "));
mysql_query($sql) or die (error("Can not insert dummy content. "));
mysql_query($sql) or die (error("Can not insert dummy content. "));
mysql_query($sql) or die (error("Can not insert dummy content. "));
echo("Dummy Text Added");
}
?>

tataencu
06-24-2007, 04:03 AM
thanks. i did manage to do the script myself and used include and it updates perfectly.

the only thing i didn't figure out is how to determine the way to get the address of the webpage where the advert is displayed...

any ideas on that?