473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need advice on which way is the best to pass variables

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
7 2210
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
"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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ben Binskin | last post by:
Im rather new to developing mysql/php applications and am after some advice on handling user validation for a web based system, ive implimented a number of ways and would like to know which way is...
8
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link,...
13
by: EggsAckley | last post by:
Hi: I have a file that I have been told is a SQL Server backup from a server somewhere. The file is about 200MB in size I am trying to create the database on my local server using RESTORE. I...
4
by: Marquisha | last post by:
If this is off-topic, please forgive me. But I thought this might be the perfect spot to get some advice about how to proceed with a project. Working on a Web site design for a nonprofit...
4
by: Bob | last post by:
Hallo, I have to make a web application in Javascript/ASP for tenniscourt reservation (based on Access database). I would like to do everything with one page, because the user must be able to...
1
by: Larry Neylon | last post by:
Hi, I'm working on a VBScript application on IIS6 and I'm looking for some advice about the best way of replacing or improving session variable usage. The application is in a secure extranet...
6
by: encoad | last post by:
Hi everyone, I'm new to C# and I am building website which allows users to fill out various forms. All is going well, however I'm having a bit of trouble with one particular issue. The main...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
1
by: jerger | last post by:
I have not made a program or page from start yet. I have made modifications to our signoff asp pages like changing the questions, texts, shortening field lengths etc... I also have copied the files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.