Jump to content

[SOLVED] image problem


qbox

Recommended Posts

Hi

I make html file like

index.php

<script type="text/javascript" src="http://localhost/test.php?ID=">
</script>

 

test.php file

 

<?php
header('Content-type: text/javascript');
echo "var myCounter =
{
init:function(mServer, mSesionID){
	myCounter.Site=\"".$_GET['site']."\";
	myCounter.Server=mServer;
	myCounter.IP=\"".$_SERVER['REMOTE_ADDR']."\";
	myCounter.trackingImage = new Image();

	myCounter.OnLoad();
},

OnLoad:function(){
	var newHref   = document.createElement(\"a\");
	var newImage  = document.createElement(\"img\");
	var scriptRef = myCounter.getScriptElement();

	var data=new Date();
	var mTZO=(typeof(data.getTimezoneOffset)!='undefined') ? data.getTimezoneOffset() : '';
	newHref.href = \"http://\" + myCounter.Serve + \"/counter/Statistic.php?site=\" + myCounter.Site;
	newHref.target = \"_top\";

	var mImage = \"http://\" + myCounter.Server + \"/counter/counting.php?site=\" + myCounter.Site; 
	if (myCounter.IP != \"\")
		mImage += \"&ip=\"+myCounter.IP;
	mImage += \"&w=\"+window.screen.width; 
	mImage += \"&h=\"+window.screen.height;
	mImage += \"&clr=\"+window.screen.colorDepth;
	mImage += \"&tzo=\" + mTZO;
	mImage += \"&lang=\"+escape(navigator.language ? navigator.language : navigator.userLanguage);
	mImage += \"&pg=\"+escape(document.location);
	mImage += \"&js=1\";
	if(navigator.cookieEnabled)
		mImage += \"&co=1\";
	else
		mImage += \"&co=0\";
	if(navigator.cpuClass)
		mImage += \"&cpu=\"+navigator.cpuClass;
	else
		mImage += \"&cpu=0\";

	newImage.border = \"0\";
	newImage.src = mImage;
	newHref.appendChild(newImage);

	myCounter.trackingImage.src = mImage;
},

getScriptElement:function()
{
	var refScript=null;
	refScript = document.getElementById( \"myCounter\" );
	if (refScript)
		return refScript;

	var pageScripts = document.getElementsByTagName(\"script\");
	for(var i=0;i<pageScripts.length;i++)
	{
		if (pageScripts[i].src)
		{
			var mSource = pageScripts[i].src.toLowerCase();
			if (mSource.indexOf(\"site=\" + myCounter.Site) > 0)
				return pageScripts[i];
		}
	}

	return null;
}
}
window.onload = function() { 
myCounter.init(); 
};
";
?>

 

after this all information are send to counter.php file for calculating.

But I want to print a image on the main page. I dont want to insert img tag in main page. I want somehow to show image from test.php file or counting.php file.

test.php file generate a javascript and return to the main page....

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/115290-solved-image-problem/
Share on other sites

I think that I make mistake somewhere in javascript code because the counting.php alone return the image but I cant see the image on the first page....

I put the javascript code in a separate file and run it for there. The script send the collected information to the counting.php file and the information are saved in another file but the picture arent return...

Link to comment
https://forums.phpfreaks.com/topic/115290-solved-image-problem/#findComment-592852
Share on other sites

counter.php

<?php
$name = "clock.jpg";
$fp = fopen($name, 'rb');
header("Content-Type: image/jpeg");
fpassthru($fp);
fclose($fp);

$str = $_SERVER['HTTP_USER_AGENT'];
$ary = explode(';',$str);
for($i=0;$i<count($ary);$i++){
$ary[$i] = str_replace(' ','',$ary[$i]);
$ary[$i] = str_replace('xx','x ',$ary[$i]);
}
$fout = fopen("test", "wt");
$colector = $_GET['site']."\n";							
$colector .= $_GET['ip']."\n"; 							
$colector .= $_GET['w']."x".$_GET['h']."\n";
$colector .= $_GET['clr']."\n";							
$colector .= $_GET['tzo']."\n";							
$colector .= $_GET['lang']."\n";						
$colector .= $_GET['pg']."\n";							
$colector .= $_GET['js']."\n";							
$colector .= $_GET['co']."\n";							
$colector .= $_GET['cpu']."\n";						
$colector .= $ary[2]."\n";								
$colector .= $str."\n";								
fwrite($fout, $colector);
?>

 

im writing to the file for now.

Link to comment
https://forums.phpfreaks.com/topic/115290-solved-image-problem/#findComment-593669
Share on other sites

ok...that code is good...i do get weird results in the JS though. at the end of the OnLoad function, have it write the image path out so you can see it, like so:

  OnLoad:function(){
    var newHref   = document.createElement(\"a\");
    var newImage  = document.createElement(\"img\");
    var scriptRef = myCounter.getScriptElement();
    
    var data=new Date();
    var mTZO=(typeof(data.getTimezoneOffset)!='undefined') ? data.getTimezoneOffset() : '';
    newHref.href = \"http://\" + myCounter.Serve + \"/counter/Statistic.php?site=\" + myCounter.Site;
    newHref.target = \"_top\";
    
    var mImage = \"http://\" + myCounter.Server + \"/counter/counting.php?site=\" + myCounter.Site; 
    if (myCounter.IP != \"\")
      mImage += \"&ip=\"+myCounter.IP;
    mImage += \"&w=\"+window.screen.width; 
    mImage += \"&h=\"+window.screen.height;
    mImage += \"&clr=\"+window.screen.colorDepth;
    mImage += \"&tzo=\" + mTZO;
    mImage += \"&lang=\"+escape(navigator.language ? navigator.language : navigator.userLanguage);
    mImage += \"&pg=\"+escape(document.location);
    mImage += \"&js=1\";
    if(navigator.cookieEnabled)
      mImage += \"&co=1\";
    else
      mImage += \"&co=0\";
    if(navigator.cpuClass)
      mImage += \"&cpu=\"+navigator.cpuClass;
    else
      mImage += \"&cpu=0\";
    
    newImage.border = \"0\";
    newImage.src = mImage;
    newHref.appendChild(newImage);

    myCounter.trackingImage.src = mImage;
    document.write(mImage); //Added this
  },

 

what is the path that it prints out?

Link to comment
https://forums.phpfreaks.com/topic/115290-solved-image-problem/#findComment-593922
Share on other sites

Archived

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

×
×
  • 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.