Jump to content

Archived

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

fpad77

Writing a cookie on the click of an item for inventory

Recommended Posts

Hey there, was wondering if someone could give me a hand with something, its most likely a relatively simple solution but was hoping someone could guide me the right way with it.

What I am doing is having an inventory that runs down the left of my site (portfolio site), and what I am doing is using items that you can find in the site that unlock extra things.

So if the user finds an item they click on it then it is added to their inventory.
What I have got so far in this is just use phpinclude to run a code before an image in the inventory can be displayed which goes as follows (missing out the top part, just to show its main use)

[code]
    if(isset($_COOKIE['gotkey1'])){
        echo "<a href=\"$href\"><img src=\"$image_folder/$image_name\" alt=\"You've got the key!\" /></a>";
    }else{
        echo "<a href=\"$href2\"><img src=\"$image_folder/$no_image_name\" alt=\"You need to find the item first!\" /></a>";
    }
[/code]

Theres probably better ways of doing this (if you got something better let me know, haha!), but this was my solution. My next problem is how would I correctly attatch something to a clickable image (ie- of a key, a chest etc) that when it is clicked it would write the cookie 'gotkey1', it would only need to be set for say an hour. I know how to write the cookie I just dont know how to get it to work with the click of the image.

Because I'm aware that the inventory item would only be shown once the next page is loaded (without using refresh), when you click the item you'd go to a new page that says 'you've found the key etc etc etc'

Any ideas?
Cheers,
Adam

Share this post


Link to post
Share on other sites

×

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.