/    Sign up×
Community /Pin to ProfileBookmark

Passing variable from PHP image to HTML/PHP page

Hi,

I have this code:

[code=php]<?php

//This is spiraldone.php
Header(“Content-type: image/png”);
$height=8000;
$width=8000;
$im=ImageCreate($width, $height);
[b]$fac=rand(110,130)/100;[/b]
$points=array(0=>0,0,);
while($width>5){
$points[count($points)]=$points[count($points)-2]+round($width/$fac);
$width=round($width/$fac);
$points[count($points)]=$points[count($points)-2];
$points[count($points)]=$points[count($points)-2];
$points[count($points)]=round($width/$fac)+$points[count($points)-2];
$width=round($width/$fac);

$points[count($points)]=$points[count($points)-2]-round($width/$fac);
$width=round($width/$fac);
$points[count($points)]=$points[count($points)-2];
$points[count($points)]=$points[count($points)-2];
$points[count($points)]=$points[count($points)-2]-round($width/$fac);
$width=round($width/$fac);
}
$pointsb=array_reduce($points, “rsum”);

$spia=ImageColorAllocate($im,rand(0,255),rand(0,255),rand(0,255));
$spib=ImageColorAllocate($im,rand(0,255),rand(0,255),rand(0,255));
$spic=ImageColorAllocate($im,rand(0,255),rand(0,255),rand(0,255));

$y=0;
for($x=0;$x+10<count($points);$x+=2){
$cr=array($points[$x],$points[$x+1],$points[$x+2],$points[$x+3],$points[$x+10],$points[$x+11],$points[$x+8],$points[$x+9]);
if($y%3==0){$spi=$spia;}
if($y%3==1){$spi=$spib;}
if($y%3==2){$spi=$spic;}
imagefilledpolygon($im,$cr,4,$spi);
$y++;
}
imagefilledpolygon($im,array($points[6],$points[7],$points[8],$points[9],0,0,0,8000),4,$spic);
imagefilledpolygon($im,array($points[4],$points[5],$points[6],$points[7],0,8000,8000,8000,8000,8000+$points[5]-$points[4]),5,$spib);
imagefilledpolygon($im,array($points[2],$points[3],$points[4],$points[5],8000,8000+$points[5]-$points[4],8000,0),4,$spia);

ImageString($im, 31, 5, 5, $fac.” “.$pointsb,$spia);

ImagePNG($im);
function rsum($v, $w)
{
$v = $v.”,”.$w;
return $v;
}
?> [/code]

Which is shown by:

spistart.php:

[code=php]<html>
<head>
<title>Fractal</title>
<script type=”text/javascript”>
function dozoom(a){
var a=document.getElementById(“fra”);
a.style.width=parseInt(a.style.width)*1.1;
a.style.height=parseInt(a.style.height)*1.1;
a.style.top=parseInt(a.style.top)-parseInt(a.style.height)*0.035;
a.style.left=parseInt(a.style.left)-parseInt(a.style.width)*0.04;
}
function loader(){
var a=document.getElementById(“fra”);
a.style.top=document.body.clientHeight/2-150;
a.style.left=document.body.clientWidth/2-150;
}
</script>
</head>
<body onload=”loader()”>
<img src=”spiraldone.php” style=”width:300px; height:300px; position:absolute; left:0px; top:0px;” onclick=”dozoom()” id=”fra” />
<imput type=”button” value=”Down!” onclick=”document.getElementById(‘fra’).style.top=parseInt(document.getElementById(‘fra’).style.top)+25;”></body>
</html>[/code]

How do I pass the value of the variable $fac from spiraldone.php to a javascript variable in spistart.php?

Thanks in advance,

Neil

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@silent11Oct 19.2004 — could you have the first script write the value to a file on the server, then have the second php script read the value, writing the JS variable into the html page?
Copy linkTweet thisAlerts:
@neil9999authorOct 20.2004 — Good idea, I'll have a go.

Thanks,

Neil
Copy linkTweet thisAlerts:
@neil9999authorOct 20.2004 — Just thought - what if two users were viewing spistart.php at the same time? The var $fac in spiraldone.php can change.

Thanks,

Neil
×

Success!

Help @neil9999 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...