/    Sign up×
Community /Pin to ProfileBookmark

Passing Variables w/o address string

Hey guys,

One of my clients uses a host that doesn’t allow variable passing/modification via a URL (ie: snap.php?wut=yes). The solution I’ve been using to pass data from page to page has been $_POST variables and making forms out of everything, but this isn’t as flexible as I’d like. Also, people get the “This Page has been loaded from POST Data” pop up if they try to navigate away… which is lame.

The latest request the client has given is a drop-down menu that loads a pop-up window of dynamic content. I have no idea how to do that via forum submission.

Any ideas? In general, do you have any tips for better variable handling?

If you have any suggestions, such as learning sessions (which comes to mind), can you please provide a link to some resource that you’ve found helpful?

Thanks!

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@bokehSep 19.2006 — I've never heard of this before. I'd change host.
Copy linkTweet thisAlerts:
@doodler85authorSep 19.2006 — I've never heard of this before. I'd change host.[/QUOTE]
So using URL-transmitted variables is standard practice?
Copy linkTweet thisAlerts:
@bokehSep 19.2006 — So using URL-transmitted variables is standard practice?[/QUOTE]Not only is it standard practice but it is the correct method by which to send any idempotent request.
Copy linkTweet thisAlerts:
@doodler85authorSep 19.2006 — Not only is it standard practice but it is the correct method by which to send any idempotent request.[/QUOTE]
Would you mind explaining that in more detail? I think the host believes it's a security risk. I've been told by someone else as well that they disable ... i can't remember what it is called, but the option enabling url-variable transfer.

Thanks!
Copy linkTweet thisAlerts:
@NogDogSep 19.2006 — The "get" method (URL query string) is normally preferred when sending data that is only to be used for "read only" type operations. A typical example of this is search queries. Note that Google transmits your search queries via a URL query string; and I suspect the folks at Google have at least a little idea about what they are doing. One obvious advantage is that you can bookmark a query result, but if it it were transmitted via the post method you could not.

The post method should be used for data which will potentially change something, for instance an e-business order form or a forum registration form. (Think of things where you would [i]not[/i] want the user to be able to bookmark the results page and thereby submit a new request each time they accessed that bookmark.)
Copy linkTweet thisAlerts:
@doodler85authorSep 19.2006 — [COLOR=Silver]That's what I figured... I think I'm going to email his host and ask if they can change the settings. It's already been a big pain in the ass. If they are resistant/ignorant about the whole deal, is it possible for me to do it via FTP, somehow?[/COLOR]

Ok, I figured it out. Apparently the default configuration for register_globals in PHP 4.0 and higher is OFF, which disables URL-string variables. I'm surprised you guys haven't run into this as well... perhaps your servers were configured differently due to its annoyance.

His server had a PHPconfig module in the control panel, so I fixed the problem.

Let me know if you have any additional thoughts or questions.

Thanks!
Copy linkTweet thisAlerts:
@NogDogSep 20.2006 — Not exactly, register_globals instantiates global variables whose names are the same as the form or query string variable name. Regardless of the register_globals setting, those same values are stored in the $_GET array (if it's from a query string) or the $_POST array (from "post" method forms).

The current "best practice" is to leave register_globals off and always access your variable via the applicable array. So if the link to your page is "somepage.php?var1=1&var2=2", then you would access the two variables as $_GET['var1'] and $_GET['var2']. Since such access will work regardless of whether or not register_globals is enabled, always doing so makes your scripts more portable since they are independent of that configuration setting. Also, having register_globals on leaves an opening for accidental or malicious overwriting of script variables via the URL, thus the evolution to having register_globals turned off as the default setting.
Copy linkTweet thisAlerts:
@doodler85authorSep 20.2006 — Awesome, thanks man. I've been really curious as to how exactly the system worked.
×

Success!

Help @doodler85 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...