Forum Moderators: coopster

Message Too Old, No Replies

storing clicked places

Is this possible with PHP?

         

sunnydayzrback

7:04 pm on May 23, 2007 (gmt 0)

10+ Year Member



Hi,
I am working on a website where I want the user to click on two different points on a image and then store where he clicked. There will be only 6-8 clickable points(via an image link) on the image . After clicking on the two points the user will be redirected to a different page(where the two points he clicked are shown) based on the choice of his clicks . Is this possible with PHP? If not how do u think this is possible?
Thanks in advance.

Demaestro

7:25 pm on May 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have the clicks result in a database entry as well as a page load... just capture and write all the info you want to the db.

cameraman

7:59 pm on May 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use javascript to capture the coordinates in an onclick event. For the first click you could either send it to a php script using AJAX, or just store it in variables. Then on the second click you send the whole thing to a php script for processing and redirection to the appropriate page.

sunnydayzrback

10:14 am on May 24, 2007 (gmt 0)

10+ Year Member



There are only 6-8 clickable places on the image. Is there a way through which i can assign a particular id to a clickable place and store it via php?

trillianjedi

10:46 am on May 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the destination URL of each clicked link unique? If so, you could grab that in your PHP script using:-

$image_clicked = $_SERVER['HTTP_REFERER'];

If it's not unique, you could make it unique with an anchor (#) on each URL, like:-

http://www.example.com/link.html#1
http://www.example.com/link.html#2
http://www.example.com/link.html#3

Then split that inside the callee script:-

$image_clicked = $_SERVER['HTTP_REFERER'];
$image_id = explode("#", $image_clicked);

As mentioned above, if you wrap the callee script into an AJAX request, you can obtain that data without the page reloading. You could store that server-side, or perhaps, given it's only 2 vars you need, store it client-side using cookies.

Sounds like an interesting user-interface being developed ;)

sunnydayzrback

8:10 pm on May 25, 2007 (gmt 0)

10+ Year Member



Hi Trillian,
Thanks for the prompt reply, but i have a problem. Here first i allow the user to click on two points then if i get the data from the two points in the script i will direct them to another page depending on the points he selected.

So if the home url is [localhost...] then the two image links are [localhost...] and
[localhost...]

but using HTTP_REFERER, I am not able to store these two values (#1 and #2) when i click on them because they are on the same page. Is there any way to do this without linking them(the two image maps) to a different page?

Thankyou.

trillianjedi

8:55 am on May 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah yes, of course. You're right, anchors wouldn't work - you'd need to use a variable in the URL:-

http://www.example.com?clicked=1

TJ