473,597 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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........ ...........VALU E='<?php>$MyVar iable</?>";

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 2221
Message-ID: <Oe_Lh.9244$zx. 4647@trndny05fr om 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 011000100110110 0010000000110
001101101011011 001000110111101 100111001011
100110001101101 111001011100111 010101101011
Mar 21 '07 #2
"Gladen Blackshield" <gl****@verizon .netwrote in message
news:Oe_Lh.9244 $zx.4647@trndny 05...
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 "httpreques t" 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...@REMOVEo ptusnet.com.auw rote:
"Gladen Blackshield" <gla...@verizon .netwrote in message

news:Oe_Lh.9244 $zx.4647@trndny 05...
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 "httpreques t" 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@trndny 05...
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........ ...........VALU E='<?php>$MyVar iable</?>";

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
5104
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 better in regards to security etc, here are the following ways i have implimented this in the past: a) user submits via form login/pass, mssql db is accessed via a no login no pass account, and a basic "select from subscribers where user=$blah and...
8
4213
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, which when you click it bookmarks the site (much easier). The favicon is never saved if the site is bookmarked this way. Does anyone have any ideas how to fix this?? This is the code: <script language="JavaScript">
13
2128
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 created the backup device, associated it with a backup name etc., copied the file into the backup dir. When I run the RESTORE command, Query Analyzer tells me the database
4
2298
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 organization, and I'm donating the work. Haven't done Web work in a while, and things have changed since I last did anything of this magnitude. I'm looking for a solution that will enable me to edit pages easily and in totally WYSIWYG fashion, while...
4
1417
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 change his day, hour or tenniscourt choice before really reserving it . I tried like this: The first SELECT contains the date (next 30 days) and is filled dynamically. No problem. When the date is chosen (by clicking), the second SELECT must...
1
1975
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 environment. Currently the application has a search customers page with 10 search fields which list the results below the search fields. The requirement for this screen was that the user could return to this result page at any point from any page...
6
1496
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 page enables users to enter information, and connect to other pages where they can enter additional details. After entering those additional details on the other pages, they are redirected back to the main page. I know I could use Session...
13
3099
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 sorts of clients. Mine are all small businesses whose sites will never reach those sorts of scales. I deal with businesses whose sites get maybe a few hundred visitors per day (some not even that much) and get no more than ten orders per day....
1
3598
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 and reused them for other domains asp 1: Basically I have a signoff asp script... that asks a. name b. email address (then submit).. this data is written to a sub folder's text file with the same name signoff.txt if the signoff.asp is...
0
7969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7886
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8035
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.