Page 1 of 1

Help with some PHP coding

Posted: Sat Oct 26, 2013 8:23 pm
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

Re: Help with some PHP coding

Posted: Sun Oct 27, 2013 7:31 am
by Celauran
Can I host this on Dropbox and use PHP?
No. You'll need a proper webhost with PHP installed.

Re: Help with some PHP coding

Posted: Tue Oct 29, 2013 4:42 am
by Durfsurn
A friend of mine has a server with PHP installed. Next step?

Thanks from a n00b at coding-
Durfsurn

Re: Help with some PHP coding

Posted: Tue Oct 29, 2013 9:59 pm
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.

Re: Help with some PHP coding

Posted: Tue Nov 12, 2013 1:24 am
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.

Re: Help with some PHP coding

Posted: Tue Nov 12, 2013 2:39 pm
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.

Re: Help with some PHP coding

Posted: Fri Nov 15, 2013 3:58 am
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

Re: Help with some PHP coding

Posted: Sun Nov 24, 2013 11:36 pm
by Durfsurn
BUMP

Re: Help with some PHP coding

Posted: Mon Nov 25, 2013 11:53 pm
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.

Re: Help with some PHP coding

Posted: Tue Nov 26, 2013 3:37 am
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

Re: Help with some PHP coding

Posted: Tue Nov 26, 2013 7:01 am
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.

Re: Help with some PHP coding

Posted: Tue Nov 26, 2013 12:13 pm
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.

Re: Help with some PHP coding

Posted: Tue Nov 26, 2013 11:48 pm
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

Re: Help with some PHP coding

Posted: Wed Nov 27, 2013 5:56 am
by Celauran
Take a look at setcookie. To learn PHP, I'd recommend PHP the Right Way as a great starting point.