Forum Moderators: coopster

Message Too Old, No Replies

map and php

passing x and y coords to a php file

         

dhiggerdhigger

12:10 pm on Jan 13, 2005 (gmt 0)

10+ Year Member



I'm trying to set up a server side image map, so that when a user clicks on an image (say, at [120,130]), I end up loading a file such as
www.example.com/result.php?x=120&y=130

What do I put in the .map file? I don't want to specify a URL for every single pixel, like

rect result.php?x=120&y=130 120,130 120,130

..I'm not even sure that that would work. For a 256*256 image, this would constitute 65536 lines in the .map file!

Can you suggest a short syntax which passes the x and y coords in a url?

Thanks
Dave Higgins

mcibor

6:56 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This isn't a php function at all.

What you have to do is to apply javascript. I found some scripts, that get mouse position, however relatively to the whole page, not just the image.
here's the code taken from [codelifter.com...]

<script language="JavaScript1.2">
<!--

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is,!IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {

 if (IE) { // grab the x-y pos.s if browser is IE

 tempX = event.clientX + document.body.scrollLeft

 tempY = event.clientY + document.body.scrollTop

 } else { // grab the x-y pos.s if browser is NS
]
 tempX = e.pageX

 tempY = e.pageY

 } 

 // catch possible negative values in NS4

 if (tempX < 0){tempX = 0}

 if (tempY < 0){tempY = 0} 

 // show the position values in the form named Show

 // in the text fields named MouseX and MouseY

 document.Show.MouseX.value = tempX

 document.Show.MouseY.value = tempY

 return true

}

//-->
</script>

I hope this helps you somehow. If not, try posting this discussion at the javascript forum.

Best regards
Michal Cibor

And even the mirrors shall be on our side!

coopster

7:34 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Also...


Question:

I'm trying to use an <input type="image"> tag, but the $foo.x and $foo.y variables aren't available. $_GET['foo.x'] isn't existing either. Where are they?

Answer:

PHP and HTML FAQ [php.net]

dhiggerdhigger

12:36 pm on Jan 14, 2005 (gmt 0)

10+ Year Member



Thankyou both for your replies. It seems the $_GET['foo_x'] method from the FAQ is exactly what I needed to know about.

Dave