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
Share on other sites

you look like you are on the right track...counter.php just needs to return an image. is that what you are having problems with...returning an image? is it a static image or one dynamically created using the GD library?

Link to comment
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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