Jump to content

Rotating Paid To Click Banners


Ache

Recommended Posts

I have a csv file that holds:ID,clicks,value,UserName,link_url,banner_urlID = the link IDClicks = amount of maximum clicks on the link/bannerUserName = Name of the user who bought the clicksLink_url = url of the site to open (in new tab)banner_url = url to where the banner is placed.What I want is a page that shows 1 available link/banner at a time.The link should open the url in a new tab when a user clicks on it.After clicking it should show the next url/banner in the file.This should be repeated until all have been shown/clicked.I know how to read a csv file and display it's contents, but have no clue on how to get the above to work.Please help me out.

Link to comment
Share on other sites

Questions:How many unique IDs/banner are there? (I'm entertaining the idea of loading all the data into a javascript array.)Do you want the page with the banners to reload when a user clicks, or would you prefer that just the banner changes? (I'd rather not scare Ache with AJAX if we don't have to.)You say you can read and display the csv data. Do you mean you know how to load it into an array and get the values from the array?

Link to comment
Share on other sites

No Ajax please, trying to learn PHP. So one thing at a time. Reloading the page with the (not yet clicked) banners sounds fine to me. The amount of unique IDs/Banners will be low (25-50) in the beginning, but if the site is a succes it can be (estimated) about 250-500. What I have sofar is:

<?php// Include config file	include ("sys-config.php");// Read the csv file with possible clicks into an array	$maxlinelength = 1000;	$fh = fopen($dataBanners, 'r');	$firstline = fgetcsv($fh, $maxlinelength);	$cols = count($firstline);	$row = 0;	$inventory = array();	while ( ($nextline = fgetcsv($fh, $maxlinelength)) !== FALSE )		{			for ( $i = 0; $i < $cols; ++$i )				{					$inventory[$firstline[$i]][$row] = $nextline[$i];				}				++$row;			}	fclose($fh);?>

And the csv file

ID,Value,Clicks,UserName,Link_url,Banner_url1,3,1000,Google,http://www.google.com,http://www.logoogle.com/images/logooward/january%2005/hot-red-google-logo.gif2,4,2000,Nu,http://nu.nl,http://www.nu.nl/images/logo_nu_nl.gif

Link to comment
Share on other sites

This does the trick. Since you're only producing one banner, there is no need for any looping. You read the whole file into an array. When a user visits your page, PHP looks for a cookie. If there is none, it sets the index to 1 and gets the second line of your file. Then it stores a cookie on the browser. Each time this happens, the cookie value is incremented. When PHP finds the cookie, its value is used as the index for getting the correct line from the file. A user who goes more than 30 days without visiting your site has the cookies cleared, and the indexing starts fresh. You can change that easily.Because you want the link to open in a new window, the code uses the deprecated target attribute. So it will not validate. But it does work.I've only printed the essential code here. You will have to integrate it into your own code on your own.

	$index = isset($_COOKIE['banner']) ? $_COOKIE['banner'] : 1;	$banners = file($dataBanners);	$str = trim($banners[$index]);	$my_banner = explode(',', $str);	$len = count($banners);	$new = ($index < $len - 1) ? $index + 1 : 1;	setcookie ("banner", "$new", time() + 60 * 60 * 24 * 30); // expires in 30 days	$str = "<a href='{$my_banner[4]}' target='_blank'><img src='{$my_banner[5]}'></a>";	echo $str;

Link to comment
Share on other sites

Thank you very much. This exactly the part that I couldn't figure out. I'm pretty sure I can do the rest myself. Since the user has to be credited for each click, I will change the code so it opens the url, credit a user and reloads the page so the next banner is shown. But that should be possible if I create a function that does those three things. But I'm not stuck anymore and have the beginning. The rest will probably take me a few hours, but that is ok. Learning takes time.Again than you.Eddy

Link to comment
Share on other sites

I made it like this, but a new page is not opening. Ik get url not found. What am I overlooking?

 // Cookie expires in 30 days 	setcookie ("banner", "$new", time() + 60 * 60 * 24 * 30);	?>		<a href="<?php openLink() ?>"><?php echo ("<img src='{$my_banner[5]}'>")?></a>	<?phpfunction openLink()		{			echo ("<script>window.open('$my_banner[4]','welcome','fullscreen=yes,scrollbars=yes');</script>");		}

Link to comment
Share on other sites

echo ("<script>window.open('{$my_banner[4]}','welcome','fullscreen=yes,scrollbars=yes');</script>");Array members inside quotation marks must be surrounded by curly braces. You did it correctly in the image tag, but missed it here.

Link to comment
Share on other sites

Well, it is not the braces. I keep getting:The requested URL /leden/<script>window.open('','welcome','fullscreen=yes,scrollbars=yes');</script> was not found on this server.Strange thing though is that is I test it like:

function openLink(){	echo ("<script>window.open('{$my_banner[4]}','welcome','fullscreen=yes,scrollbars=yes');</script>");}openLink();

It is working. Also if I place that line in a if statement it is working. In my opinion it has something to do with the way the echo string is handled within a function. So I tried it as:

function openLink(){?><script>window.open('{$my_banner[4]}','welcome','fullscreen=yes,scrollbars=yes');</script><?php}

But it gave the same url not found error.I also tried:$strtest = "<script blah blah"echo $strtestBut that also gives the url not found

Link to comment
Share on other sites

After the page downloads, view the source code to see what is actually getting echoed. It's obviously not what you think. Seeing what really happens should lead you to the correct changes. You haved showed us the openLink function, but not where it exists in the whole document. The error code looks like it's in the wrong place, or that you are assembling strings in the wrong order.

Link to comment
Share on other sites

Seems to me, you mixed it all up.. Check this out

<html><head><?php$mybanner_url = "http://www.w3schools.com";$my_banner_img = "banner.gif";?><script>function openwindow(){window.open("<?=$mybanner_url?>","welcome","menubar=1,resizable=1,width=350,height=250");}</SCRIPT></head><body><?php$str = "<a href='{$mybanner_url}' target='_blank'><img src='{$my_banner_img}'></a>";echo $str;?><?php echo ("<a href='java script: openwindow()'>open Sesame</a>"); ?></body></html>

Works like a charmHere is an HTML output:

<html><head><script>function openwindow(){	window.open("http://www.w3schools.com","welcome","menubar=1,resizable=1,width=350,height=250");}</SCRIPT></head><body><a href='http://www.w3schools.com' target='_blank'><img src='banner.gif'></a><a href='java script: openwindow()'>open Sesame </a></body></html>

Hope you'll get out of this what you need! :)E.g.echo ("<a href='java script: openwindow()'><img src='<?=$my_banner_img?>'> </a>"); Edit: NOTE:I guess Codebox breaks word javascript into java script in above example

Link to comment
Share on other sites

I now know where it went wrong. I thought it was the function, but that is where I went wrong. The real problem is within the : echo '<a href=' . openLink($my_banner[4]) . '><img src=' . $my_banner[5] . '></a>';It is almost working as I want it. Just two things left to fix.1] It now opens the url automaticly and that should only happen when a user clicks on the banner. 2] After the last banner is shown/clicked it starts again with the first one. The user should not be able to click for 24 hours (1 day) after the last banner is clicked.Other than getting closer to a working solution. I have learned some new things :-)

<?php// Include config file	include ("sys-config.php");// Read the csv file with possible clicks into an array	$maxlinelength = 1000;	$fh = fopen($dataBanners, 'r');	$firstline = fgetcsv($fh, $maxlinelength);	$cols = count($firstline);	$row = 0;	$inventory = array();	while ( ($nextline = fgetcsv($fh, $maxlinelength)) !== FALSE )		{			for ( $i = 0; $i < $cols; ++$i )				{					$inventory[$firstline[$i]][$row] = $nextline[$i];				}				++$row;			}	fclose($fh);// Show a available banner	$index = isset($_COOKIE['banner']) ? $_COOKIE['banner'] : 1;	$banners = file($dataBanners);	$str = trim($banners[$index]);	$my_banner = explode(',', $str);	$len = count($banners);	$new = ($index < $len - 1) ? $index + 1 : 1; // Cookie expires in 30 days 	setcookie ("banner", "$new", time() + 60 * 60 * 24 * 1);	echo '<a href=' . openLink($my_banner[4]) . '><img src=' . $my_banner[5] . '></a>';// If the user has clicked the banner:// 1] show the site in new window/tab// 2] add credit(s) to the users account// 3] reload this page so the next available banner will be shownfunction openLink($temp)		{			echo ("<script>window.open('{$temp}','welcome','fullscreen=yes,scrollbars=yes');</script>");		}?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...