Php iframe pixel Question

brentb

(__TNT__)~
Jun 13, 2011
281
4
0
So I made an iframe that links to a php file. This php file just grabs the variable from the iframe url and writes it to the database...

Why does this not work?

If i load the pixel directly it does but in the iframe it does not...

Am I doing this wrong?
 


The iframe loads a PHP file, or links to a PHP file? iframes are pretty stingy with what they let you access. Have you considered updating the database using ajax instead? There are some pretty smart folks around here who might have more insight.
 
To be honest, I only know html and php...

I am considering using an img pixel to accomplish the same task however with the iframe, it gives me the ability to include other peoples pixels in the iframe, that was the main reason behind it...

Not sure if I can figure the img out though...

I just am trying to do this in the same way real affiliate software does this, because I am building a custom software for a very niche type of affiliate offer that is currently untapped.
 
Code:
<iframe scr="http://www.247trend.com/track/pixel/" height="1" width="1" frameborder="0" scrolling="no"></iframe>

Code:
<img scr="http://www.247trend.com/track/pixel/index.jpg" height="1" width="1">

I have been trying these two ways... neither is working...

This is included in the img example only:
Code:
header('content-type: image/jpeg');

Code:
<?php

//Database connection variables
$host = "localhost";
$user = "NO";
$pass = "NO";
$db = "NO";

//Connects To Database
$con = mysql_connect($host,$user,$pass);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($db, $con);

mysql_query("INSERT INTO track (id,fieldid,extra1)
VALUES ('1','2','2')");
?>
 
LOL.... you aren't passing anything in your code. Dude, here is a simple solution:

Code:
<img scr="http://www.247trend.com/track/pixel/index.jpg?id=1&fieldid=2&extra1=2" height="1" width="1">

Then have the script read the attached string and call it a day.

The problem with your script, is you are assuming that the php img file, has the variables, which you did not pass from the main php file. You are assuming it's one continuos php file, when it is completely a separate file, with no attached "required" files. Unless this was one continuous php file, which in that case you would not need a tracking pixel, you are leaving out the variables.

I would strongly consider using ajax for this task, it's a lot simpler.
 
No no no... I am not trying to pass anything at this point. Thats why I have hard coded in the values 1 2 2 so I don't need to mess with passing the info yet. I just want it to write 1 2 2 into the database.

It does this if I access the pixel directly but it will not through the image or the iframe.
 
I ran into a similiar problem a couple of years ago. I think it has something to do with the header tag content/image or something. Also it has to output an proper image i believe, even if its an all white 1x1 box. I solved the problem, but in perl.
 
No no no... I am not trying to pass anything at this point. Thats why I have hard coded in the values 1 2 2 so I don't need to mess with passing the info yet. I just want it to write 1 2 2 into the database.

It does this if I access the pixel directly but it will not through the image or the iframe.

There are only a couple of things that can be wrong here:

  1. You're not putting in the right info to connect to the DB. Check that first. However you should see an error message.
  2. Your DB doesn't accept connections from where you are trying to connect from. This would be an issue if you're trying to connect from anywhere except localhost. However you should see an error message.
  3. Which leaves the most obvious, the table, or fields your are referencing are wrong. They either don't exist, or the wrong type, or they are spelled wrong.
You should put, echo mysql_error(); at the bottom of your script to see if it spits an error message after the insert.

Also I always write my inserts as so, to avoid any freaky shit from happening:
Code:
mysql_query("INSERT INTO track (`id`,`fieldid`,`extra1`) VALUES ('1','2','2')");
Lots of hurp durp up in here.
 
That it!!!! They mysql database is probably not allowed to be called from the main php file. This could happen when your database is located on a physical separate hard drive or IP but your are on a shared host or something which puts the other files on a different hard drive, even though it might still work with the "localhost". It can also be a permissions problem.
 
You will have to whtelist the Ip address of the main php's sever ip. Like stated above look at the mysql error code that is being spit out. You can set it to email you the error code, since you are trying to render an image file.
 
  1. You're not putting in the right info to connect to the DB. Check that first. However you should see an error message.
  2. Your DB doesn't accept connections from where you are trying to connect from. This would be an issue if you're trying to connect from anywhere except localhost. However you should see an error message.
  3. Which leaves the most obvious, the table, or fields your are referencing are wrong. They either don't exist, or the wrong type, or they are spelled wrong.

1. It works if I access the file directly so the DB connect info is right.

2. Currently I am doing it on the same domain, same server, so that shouldn't be an issue for right now.

3. They are right because it enters the data if I run the pixel directly.

I will try the error check and see if it outputs anything...
 
You will have to whtelist the Ip address of the main php's sever ip. Like stated above look at the mysql error code that is being spit out. You can set it to email you the error code, since you are trying to render an image file.

It should not have to do this, or maybe I am going about this wrong. When its done, I want it to work like an affiliate tracking software so I can give pixels to people running offers to place on conversion pages, no way is any tracking software whitelisting IPs so maybe I am just using the wrong methods here for tracking?
 
I added the ` to avoid the freaky shit lol thats funny man...

I added the mysql error output and nothing outputs from either the page with the img/iframe pixel nor when i access the pixel directly.
 
I added the ` to avoid the freaky shit lol thats funny man...

I added the mysql error output and nothing outputs from either the page with the img/iframe pixel nor when i access the pixel directly.

I know nothing is going to output, that why I stated to have the program email it to you. Think about it, you are attempting to replicate an image, you the only output should be the image code. You have to have the program email you the error output.
 
I added the ` to avoid the freaky shit lol thats funny man...

I added the mysql error output and nothing outputs from either the page with the img/iframe pixel nor when i access the pixel directly.

Stick this at the top of your file:

Code:
ini_set('display_errors', 1);
error_reporting(-1);

This will force error output regardless of the settings in your php.ini file, because if you're on shared hosting or whatnot they will have the error level turned down.
 
Also I always write my inserts as so, to avoid any freaky shit from happening:
Code:
mysql_query("INSERT INTO track (`id`,`fieldid`,`extra1`) VALUES ('1','2','2')");
Lots of hurp durp up in here.

Even better (more readable):

Code:
mysql_query("INSERT INTO track
SET id = 1,
fieldid = 2,
extra1 = 2;
");
reads even better with proper indenting

also, OP - you should always catch your errors
have mysql_query return a result and then check for !$result (failure)