By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

Need advice on which way is the best to pass variables

P: n/a
Hello All!

Still very new to PHP and I was wondering about the easiest and simplest way
to go about doing something for a project I am working on. I would simply
like advice on what I'm asking so I can go and learn it myself through doing
(best way for me).

I am building a card game as a learning-project as it involves many (to most
of the) things that I would like to learn to do with PHP.

This project is intended to be Flat-File only, no SQL connections. I'd much
rather not use cookies for this if at all possible.

The project involves loading different pictures on the top of the page while
the game is being played. That's easy enough to do, but it forces a refresh
when the picture changes.

which brings me to needing to find the porper solution to the following:

I am needing to keep roughly 12 or so variables tracked during the game.
This should be automatically parsed when the user clicks on 'DEAL' or
whatever to go to the next turn (going to the next turn would result in a
different picture being shown and thus force a refresh of the page)

I am not asking particularly HOW to pass the variables, as I have 3 options
that should work, I am simply asking which of these ideas seems to be the
most correct way to accomplish this task.

Method 1: pass the PHP variable through the form from the VALUE.....such as
echo "<input...................VALUE='<?php>$MyVariable </?>";

Method 2: write the variables to a text file (or some other file) and read
the file at the beginning of the turn and then write to the file at the end
of the turn, using the FILE commands.

Method 3: Start a session at the onset of the game and declare the
variables at session variables and work with those using the SESSION libray.

I am relatively inexperienced with PHP but am fluent with other languages,
so the concepts are not foreign, only the syntax.

So your guidance on the best way to pass an arbitrary number of variables
during the refresh would be most helpful to point me in the direction that I
need to focus my studies on.

thanks All!

Mar 20 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Message-ID: <Oe_Lh.9244$zx.4647@trndny05from Gladen Blackshield
contained the following:
>So your guidance on the best way to pass an arbitrary number of variables
during the refresh would be most helpful to point me in the direction that I
need to focus my studies on.
The disadvantage of hidden fields is that they are visible if you view
the source. And of course they can be changed by the user which might
not be what you want in a game.

I'd say sessions are your best bet provided they game is designed to run
over a relatively short time period. If you want extended play (over a
number of sessions) then files or database is the way to go.

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Mar 21 '07 #2

P: n/a
"Gladen Blackshield" <gl****@verizon.netwrote in message
news:Oe_Lh.9244$zx.4647@trndny05...
Hello All!

Still very new to PHP and I was wondering about the easiest and simplest
way
to go about doing something for a project I am working on. I would simply
like advice on what I'm asking so I can go and learn it myself through
doing
(best way for me).

I am building a card game as a learning-project as it involves many (to
most
of the) things that I would like to learn to do with PHP.

This project is intended to be Flat-File only, no SQL connections. I'd
much
rather not use cookies for this if at all possible.

The project involves loading different pictures on the top of the page
while
the game is being played. That's easy enough to do, but it forces a
refresh
when the picture changes.

which brings me to needing to find the porper solution to the following:

I am needing to keep roughly 12 or so variables tracked during the game.
This should be automatically parsed when the user clicks on 'DEAL' or
whatever to go to the next turn (going to the next turn would result in a
different picture being shown and thus force a refresh of the page)
I think you should take a look at AJAX, or simply the "httprequest" object.
That way you can send and recieve data from the server, and display it,
without having to refresh the page.
You could also create a session if you want your data to persist during the
game.
HTH
Vince Moran
Mar 21 '07 #3

P: n/a
On 21 Mar, 00:46, "Vince Morgan" <vin...@REMOVEoptusnet.com.auwrote:
"Gladen Blackshield" <gla...@verizon.netwrote in message

news:Oe_Lh.9244$zx.4647@trndny05...
Hello All!
Still very new to PHP and I was wondering about the easiest and simplest
way
to go about doing something for a project I am working on. I would simply
like advice on what I'm asking so I can go and learn it myself through
doing
(best way for me).
I am building a card game as a learning-project as it involves many (to
most
of the) things that I would like to learn to do with PHP.
This project is intended to be Flat-File only, no SQL connections. I'd
much
rather not use cookies for this if at all possible.
The project involves loading different pictures on the top of the page
while
the game is being played. That's easy enough to do, but it forces a
refresh
when the picture changes.
which brings me to needing to find the porper solution to the following:
I am needing to keep roughly 12 or so variables tracked during the game.
This should be automatically parsed when the user clicks on 'DEAL' or
whatever to go to the next turn (going to the next turn would result in a
different picture being shown and thus force a refresh of the page)

I think you should take a look at AJAX, or simply the "httprequest" object.
That way you can send and recieve data from the server, and display it,
without having to refresh the page.
You could also create a session if you want your data to persist during the
game.
HTH
Vince Moran
sessions are certainly your best bet, as 2 and 3 are essentially the
same (sessions are flat files), except the hard work is done for you
already.

if you intend your game to last across sessions (browser close /
logout etc...) then you will have to serialise the session data and
write to a flat file, and deserialise back into a session later. The
way you keep track of those files is up to.

you would write your app using $_SESSION['var_name'] instead of
$var_name, it's almost as simple as that, using sessions avoids
prediction attacks which might leave your game open to cheats (if you
didn't code sufficiently randomised filenames etc...), although in a
LAN environment, sessions are not enough protection from an ARP/proxy
cheater - but it all adds to the fun huh!

Mar 21 '07 #4

P: n/a
I can't add anything to the great advice you've gotten except to point
out that sessions do involve using a cookie, something you mentioned
you didn't want to do.

--Kenoli

Mar 21 '07 #5

P: n/a
On Mar 21, 3:08 pm, "kenoli" <kenol...@gmail.comwrote:
I can't add anything to the great advice you've gotten except to point
out that sessions do involve using a cookie, something you mentioned
you didn't want to do.
Sessions do not need to involve a cookie if you include the session ID
on every URL a user clicks on.

What you will struggle with, however, is storing the state of play of
the game in progress without writing to a database or file at some
point.
Mar 21 '07 #6

P: n/a
On Mar 21, 3:13 pm, "Aetherweb" <jeffs...@gmail.comwrote:
On Mar 21, 3:08 pm, "kenoli" <kenol...@gmail.comwrote:
I can't add anything to the great advice you've gotten except to point
out that sessions do involve using a cookie, something you mentioned
you didn't want to do.

Sessions do not need to involve a cookie if you include the session ID
on every URL a user clicks on.

What you will struggle with, however, is storing the state of play of
the game in progress without writing to a database or file at some
point.
It has to be said that *any* data passed as a result of playing the
game will be alterable, but the idea behind using a session is that
you dont have to carry the full weight of the variables on each round
trip.
You could, say encrypt a string and send it as a hidden field, (rather
like the postback, but using real encryption)
there are many possibilities, but ultimately the convienience of a
session wins through.
Although it does involce a cookie - it is one handled entirely with
javascript as a HTTP header, and does not need to be interacted with
in any way with client logic, the logic is all server side, the only
thing the client does is handle the posting of the data0
When using the session ID in the URL as a query string, (or indeed
storing it somewhere in the markup) you trade the lack of a cookie,
with the high visibility to a casual onlooker (or proxy log etc..) of
the session ID which can enable full session privs without needing to
know the password. At least a header is slightly less obvious, but of
course is still interceptable.

Mar 21 '07 #7

P: n/a
Thanks everyone!

I dinkered around a bit with sessions last night, and once i figured out
that you cannot have anything else going on BEFORE you opena sesison, I
think that's the way to go.

since I'm making this project as my own learning experience, I'm not really
worried about security, or game hacking, etc.

thank you fro the help

Gladen
"Gladen Blackshield" <gl****@verizon.netwrote in message
news:Oe_Lh.9244$zx.4647@trndny05...
Hello All!

Still very new to PHP and I was wondering about the easiest and simplest
way to go about doing something for a project I am working on. I would
simply like advice on what I'm asking so I can go and learn it myself
through doing (best way for me).

I am building a card game as a learning-project as it involves many (to
most of the) things that I would like to learn to do with PHP.

This project is intended to be Flat-File only, no SQL connections. I'd
much rather not use cookies for this if at all possible.

The project involves loading different pictures on the top of the page
while the game is being played. That's easy enough to do, but it forces a
refresh when the picture changes.

which brings me to needing to find the porper solution to the following:

I am needing to keep roughly 12 or so variables tracked during the game.
This should be automatically parsed when the user clicks on 'DEAL' or
whatever to go to the next turn (going to the next turn would result in a
different picture being shown and thus force a refresh of the page)

I am not asking particularly HOW to pass the variables, as I have 3
options that should work, I am simply asking which of these ideas seems to
be the most correct way to accomplish this task.

Method 1: pass the PHP variable through the form from the VALUE.....such
as
echo "<input...................VALUE='<?php>$MyVariable </?>";

Method 2: write the variables to a text file (or some other file) and
read the file at the beginning of the turn and then write to the file at
the end of the turn, using the FILE commands.

Method 3: Start a session at the onset of the game and declare the
variables at session variables and work with those using the SESSION
libray.

I am relatively inexperienced with PHP but am fluent with other languages,
so the concepts are not foreign, only the syntax.

So your guidance on the best way to pass an arbitrary number of variables
during the refresh would be most helpful to point me in the direction that
I need to focus my studies on.

thanks All!

Mar 21 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.