Help with some PHP coding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Durfsurn
Forum Newbie
Posts: 7
Joined: Sat Oct 26, 2013 8:16 pm

Help with some PHP coding

Post by Durfsurn »

Code: Select all

<!DOCTYPE html>
<html>
<head>
        <title>Co-Op City Tile Selection Application</title>
        <meta charset="windows-1252"/>
        <meta name="viewport" content="width=device-width"/>
        <script>
                var counter = 0;
                function myFunction()
                {
                        var c=document.getElementById("myCanvas");
                        var ctx=c.getContext("2d");
                        if(counter == 0)
                        {
                                var img=document.getElementById("img1");
                                ctx.drawImage(img,0,0,256,256);
                        }
                        else if(counter ==1)
                        {
                                var img=document.getElementById("img2");
                                ctx.drawImage(img,0,0,256,256);
                        }
                        else if(counter ==2)
                        {
                                var img=document.getElementById("img3");
                                ctx.drawImage(img,0,0,256,256);
                               
                                counter = -1;
                        }
                        counter = counter +1;
                }
        </script>
</head>
 
<body>
 
        <img id="img1" style="display:none;" src="Yakutat-Bay-city-overlay_01.jpg" width="256" height="256" alt="Yakutat-Bay-city-overlay_01.jpg" />
        <img id="img2" style="display:none;" src="Yakutat-Bay-city-overlay_01X.jpg" width="256" height="256" alt="Yakutat-Bay-city-overlay_01X.jpg" />
        <img id="img3" style="display:none;" src="Yakutat-Bay-city-overlay_01Y.jpg" width="256" height="256" alt="Yakutat-Bay-city-overlay_01Y.jpg" />
 
        <canvas id="myCanvas" onclick="myFunction();" onload="myFunction();" width="256" height="256" style="border:1px solid #000000;">
        </canvas>
                               
</body>
</html>

That's my existing HTML/javascript code written using Netbeans, and I need some help with some PHP (server side scripting) to add to it. Can I host this on Dropbox and use PHP? If yes then what I would like to do is make the webpage remember what state the image is in. Etc if it is currently in Yakutat-Bay-city-overlay_01X.jpg (state 2) then when the next person opens the page it is in state 2 rather then the beginning (state 0).

Thanks from a n00b at coding-
Durfsurn
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Help with some PHP coding

Post by Celauran »

Can I host this on Dropbox and use PHP?
No. You'll need a proper webhost with PHP installed.
Durfsurn
Forum Newbie
Posts: 7
Joined: Sat Oct 26, 2013 8:16 pm

Re: Help with some PHP coding

Post by Durfsurn »

A friend of mine has a server with PHP installed. Next step?

Thanks from a n00b at coding-
Durfsurn
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help with some PHP coding

Post by Christopher »

Durfsurn wrote:A friend of mine has a server with PHP installed. Next step?
Durfsurn wrote: and I need some help with some PHP (server side scripting) to add to it.
Upload the above file and the PHP script with the functionality you need to your friend's server.
(#10850)
Durfsurn
Forum Newbie
Posts: 7
Joined: Sat Oct 26, 2013 8:16 pm

Re: Help with some PHP coding

Post by Durfsurn »

That's my problem I need help with the PHP coding. I was hoping someone on here could head me in the right direction.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help with some PHP coding

Post by Christopher »

Durfsurn wrote:what I would like to do is make the webpage remember what state the image is in. Etc if it is currently in Yakutat-Bay-city-overlay_01X.jpg (state 2) then when the next person opens the page it is in state 2 rather then the beginning (state 0).
Saving the state can be done several ways in PHP. You could use cookies or the PHP session system for individual users. If you want it to be accessed by multiple users then a database or some kind of cache would be needed.
(#10850)
Durfsurn
Forum Newbie
Posts: 7
Joined: Sat Oct 26, 2013 8:16 pm

Re: Help with some PHP coding

Post by Durfsurn »

I would need a database or a cache. I want it so when P1 opens http://www.mywebsite.com then changes something then when P2 opens http://www.mywebsite.com it has that change recorded and saved until further changed.\

Thanks
Durfsurn
Durfsurn
Forum Newbie
Posts: 7
Joined: Sat Oct 26, 2013 8:16 pm

Re: Help with some PHP coding

Post by Durfsurn »

BUMP
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help with some PHP coding

Post by Christopher »

Durfsurn wrote:I would need a database or a cache. I want it so when P1 opens http://www.mywebsite.com then changes something then when P2 opens http://www.mywebsite.com it has that change recorded and saved until further changed.
What is the "something" that changes? It sounds like an image rotater where a person sees the next image every time they visit the page. Those usually use a cookie.
(#10850)
Durfsurn
Forum Newbie
Posts: 7
Joined: Sat Oct 26, 2013 8:16 pm

Re: Help with some PHP coding

Post by Durfsurn »

Would a cookie suffice to save the data? Does it save it for everyone? And your right it is an "Image Rotater" thing.

Thanks a bunch -
Durfsurn
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Help with some PHP coding

Post by Celauran »

Whether it would suffice depends on your specific needs, I suppose, but that's the route I'd take. Cookies are per user. I think it's safe to assume cookies will be enabled 99+% of the time. How well they work would depend on the expiry you choose and how frequently users visit your site.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help with some PHP coding

Post by Christopher »

Agreed, a cookie would work well and be my preference. The alternative would be to set a value in the user's PHP session.
(#10850)
Durfsurn
Forum Newbie
Posts: 7
Joined: Sat Oct 26, 2013 8:16 pm

Re: Help with some PHP coding

Post by Durfsurn »

Thanks for the insight. I will try the cookie method first. Now how would I go about doing that? Do I just need to make a PHP script and have it load on the site? Also I don't know how to program in PHP so could I have some help?

Thanks guys-
Durfsurn
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Help with some PHP coding

Post by Celauran »

Take a look at setcookie. To learn PHP, I'd recommend PHP the Right Way as a great starting point.
Post Reply