Počítání kliknutí na reklamu – PHP – Fórum – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Počítání kliknutí na reklamu – PHP – Fórum – Programujte.comPočítání kliknutí na reklamu – PHP – Fórum – Programujte.com

 

Toto vlákno bylo označeno za vyřešené — příspěvek s řešením.
webdorf0
Newbie
30. 10. 2016   #1
-
0
-

Zdravím, 

Již pár dní se zabývám takovým problémem a absolutně ho nemohu vyřešit.
Potřeboval bych počítat kliknutí na reklamu a následně IP adresu a datum kliknutí uložit do databáze..

Kód reklamy vypadá: 

<!-- Kontextová reklama Sklik -->
<div id="sklikReklama_12112"></div>
<script>
	var sklikData = { elm: "sklikReklama_12112", zoneId: "12112", w: 468, h: 60 };
</script>
<script src="//c.imedia.cz/js/script.js"></script>

Potřeboval bych do databáze do tabulky IPS do sloupce ip a sloupce time 
Uložit ip a datum kliknutí 
 

IP zjistím takto:  

$ip_uzivatel = $_SERVER['HTTP_X_FORWARDED_FOR']
//uložení ip do db
$ipp = "'$ip_uzivatel'";

Ukládat do databáze takto: 

INSERT INTO `d130729_20`.`ips` ( `id` , `ip` , `time` ) VALUES ( NULL , '.$ipp.', '.$times.' );

čas v tomto fórmátu: 

$t=time();
$time=(date("Y-m-d",$t));
$times = "'%$time%'";
Nahlásit jako SPAM
IP: 89.103.172.–
peter
~ Anonymní uživatel
3982 příspěvků
31. 10. 2016   #2
-
0
-

A dal? V cem je problem?
Predpokladejme, ze ty fragmenty kodu mas ulozene v nejakem php kodu. Ktery jsi zatajil.
Podle mne by to mohlo fungovat.
Takze, co na tom nefunguje?

"'%$time%'"; - z tama ti db nejspis % odstrani. Pokud ne, pak je tu error. A nejspis hodnoty jeste nejak escapujes pres mysql_real_escape_string pro mysql
http://php.net/…e-string.php

$ip_uzivatel = $_SERVER['HTTP_X_FORWARDED_FOR']
Nejspis vis, ze tady na konci ti schazi strednik.

$time=(date("Y-m-d",$t));
Nejspis vis, ze zavorka pred date a pak na konci je zbytecna

Nespis si umis vypsat sql dotaz na obrazovku, zda je ok.
Nejspis ho umis zkopirovat do phpmyadmina a poslat do db.
Takze, predpokladejme, ze mas dotaz vyzkouseny a ze funguje. Tak, pak je otazka, kde je problem?

No, a pokud nic z toho nemas v programu, tak pak nevim, co tu delas. Inzerce, prace a zakazky je tema, kde se kupuji hotova reseni.

Nahlásit jako SPAM
IP: 2001:718:2601:26c:ec42:d6...–
webdorf0
Newbie
31. 10. 2016   #3
-
0
-

#2 peter
Už vyřešeno

Nahlásit jako SPAM
IP: 89.103.172.–
Řešení
webdorf0
Newbie
31. 10. 2016   #4
-
0
-
Vyřešeno Nejlepší odpověď

testip.php   

<?php
require "conn.php";

//Proxy IP ...
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
    $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}

$ip_uzivatel = $_SERVER['REMOTE_ADDR'];
$ipp = "'$ip_uzivatel'";

$t=time();
$time=(date("Y-m-d",$t));
$times = "'$time'";

$stmt = $pdo->query('INSERT INTO `db`.`ips` ( `id` , `ip` , `time` ) VALUES ( NULL , '.$ipp.', '.$times.' );');

?>

pod kód reklamy (od seznam.cz) - partner sklik.. 

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
        <script src="jquery.iframetracker.js"></script>
        <script type="text/javascript">
            $("iframe").iframeTracker({
              blurCallback: function(){
                $.ajax({
                    url: "testip.php"
                });
              }
            });
            
            $(document).ready(function(){
              $("#container-banner a").click(function() {
                $.ajax({
                        url: "testip.php"
                    });
              });
            });
        </script>

jquery.iframetracker.js

/**
 * jQuery iframe click tracking plugin
 *
 * @author Vincent Paré (www.finalclap.com)
 * @copyright © 2013-2015 Vincent Paré
 * @license http://opensource.org/…s/Apache-2.0
 * @version 1.1.0
 */
(function($){
	// Tracking handler manager
	$.fn.iframeTracker = function(handler){
		var target = this.get();
		if (handler === null || handler === false) {
			$.iframeTracker.untrack(target);
		} else if (typeof handler == "object") {
			$.iframeTracker.track(target, handler);
		} else {
			throw new Error("Wrong handler type (must be an object, or null|false to untrack)");
		}
	};
	
	// Iframe tracker common object
	$.iframeTracker = {
		// State
		focusRetriever: null,  // Element used for restoring focus on window (element)
		focusRetrieved: false, // Says if the focus was retrived on the current page (bool)
		handlersList: [],      // Store a list of every trakers (created by calling $(selector).iframeTracker...)
		isIE8AndOlder: false,  // true for Internet Explorer 8 and older
		
		// Init (called once on document ready)
		init: function(){
			// Determine browser version (IE8-) ($.browser.msie is deprecated since jQuery 1.9)
			try {
				if ($.browser.msie == true && $.browser.version < 9) {
					this.isIE8AndOlder = true;
				}
			} catch(ex) {
				try {
					var matches = navigator.userAgent.match(/(msie) ([\w.]+)/i);
					if (matches[2] < 9) {
						this.isIE8AndOlder = true;
					}
				} catch(ex2) {}
			}
			
			// Listening window blur
			$(window).focus();
			$(window).blur(function(e){
				$.iframeTracker.windowLoseFocus(e);
			});
			
			// Focus retriever (get the focus back to the page, on mouse move)
			$('body').append('<div style="position:fixed; top:0; left:0; overflow:hidden;"><input style="position:absolute; left:-300px;" type="text" value="" id="focus_retriever" readonly="true" /></div>');
			this.focusRetriever = $('#focus_retriever');
			this.focusRetrieved = false;
			$(document).mousemove(function(e){
				if (document.activeElement && document.activeElement.tagName == 'IFRAME') {
					$.iframeTracker.focusRetriever.focus();
					$.iframeTracker.focusRetrieved = true;
				}
			});
			
			// Special processing to make it work with my old friend IE8 (and older) ;)
			if (this.isIE8AndOlder) {
				// Blur doesn't works correctly on IE8-, so we need to trigger it manually
				this.focusRetriever.blur(function(e){
					e.stopPropagation();
					e.preventDefault();
					$.iframeTracker.windowLoseFocus(e);
				});
				
				// Keep focus on window (fix bug IE8-, focusable elements)
				$('body').click(function(e){ $(window).focus(); });
				$('form').click(function(e){ e.stopPropagation(); });
				
				// Same thing for "post-DOMready" created forms (issue #6)
				try {
					$('body').on('click', 'form', function(e){ e.stopPropagation(); });
				} catch(ex) {
					console.log("[iframeTracker] Please update jQuery to 1.7 or newer. (exception: " + ex.message + ")");
				}
			}
		},
		
		
		// Add tracker to target using handler (bind boundary listener + register handler)
		// target: Array of target elements (native DOM elements)
		// handler: User handler object
		track: function(target, handler){
			// Adding target elements references into handler
			handler.target = target;
			
			// Storing the new handler into handler list
			$.iframeTracker.handlersList.push(handler);
			
			// Binding boundary listener
			$(target)
				.bind('mouseover', {handler: handler}, $.iframeTracker.mouseoverListener)
				.bind('mouseout',  {handler: handler}, $.iframeTracker.mouseoutListener);
		},
		
		// Remove tracking on target elements
		// target: Array of target elements (native DOM elements)
		untrack: function(target){
			if (typeof Array.prototype.filter != "function") {
				console.log("Your browser doesn't support Array filter, untrack disabled");
				return;
			}
			
			// Unbinding boundary listener
			$(target).each(function(index){
				$(this)
					.unbind('mouseover', $.iframeTracker.mouseoverListener)
					.unbind('mouseout', $.iframeTracker.mouseoutListener);
			});
			
			// Handler garbage collector
			var nullFilter = function(value){
				return value === null ? false : true;
			};
			for (var i in this.handlersList) {
				// Prune target
				for (var j in this.handlersList[i].target) {
					if ($.inArray(this.handlersList[i].target[j], target) !== -1) {
						this.handlersList[i].target[j] = null;
					}
				}
				this.handlersList[i].target = this.handlersList[i].target.filter(nullFilter);
				
				// Delete handler if unused
				if (this.handlersList[i].target.length == 0) {
					this.handlersList[i] = null;
				}
			}
			this.handlersList = this.handlersList.filter(nullFilter);
		},
		
		// Target mouseover event listener
		mouseoverListener: function(e){
			e.data.handler.over = true;
			try {e.data.handler.overCallback(this);} catch(ex) {}
		},
		
		// Target mouseout event listener
		mouseoutListener: function(e){
			e.data.handler.over = false;
			$.iframeTracker.focusRetriever.focus();
			try {e.data.handler.outCallback(this);} catch(ex) {}
		},
		
		// Calls blurCallback for every handler with over=true on window blur
		windowLoseFocus: function(event){
			for (var i in this.handlersList) {
				if (this.handlersList[i].over == true) {
					try {this.handlersList[i].blurCallback();} catch(ex) {}
				}
			}
		}
	};
	
	// Init the iframeTracker on document ready
	$(document).ready(function(){
		$.iframeTracker.init();
	});
})(jQuery);
Nahlásit jako SPAM
IP: 89.103.172.–
Zjistit počet nových příspěvků

Přidej příspěvek

Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!

Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku

×Vložení zdrojáku

×Vložení obrázku

Vložit URL obrázku Vybrat obrázek na disku
Vlož URL adresu obrázku:
Klikni a vyber obrázek z počítače:

×Vložení videa

Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×
 
Podporujeme Gravatara.
Zadej URL adresu Avatara (40 x 40 px) nebo emailovou adresu pro použití Gravatara.
Email nikam neukládáme, po získání Gravatara je zahozen.
-
Pravidla pro psaní příspěvků, používej diakritiku. ENTER pro nový odstavec, SHIFT + ENTER pro nový řádek.
Sledovat nové příspěvky (pouze pro přihlášené)
Sleduj vlákno a v případě přidání nového příspěvku o tom budeš vědět mezi prvními.
Reaguješ na příspěvek:

Uživatelé prohlížející si toto vlákno

Uživatelé on-line: 0 registrovaných, 19 hostů

Podobná vlákna

Nabízím e-mailovou reklamu — založil Michail

Akcia po kliknutí — založil Peter125

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý