473,416 Members | 1,558 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,416 software developers and data experts.

Forcefuly setting '$HTTP_GET_VARS'

Hi,

Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS

$HTTP_GET_VARS['foo'] = 'bar'?
If yes, why? and how can i pass value between one page and the other without
using the url?

Regards,

Sims
Jul 17 '05 #1
4 4335
> Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS

$HTTP_GET_VARS['foo'] = 'bar'?
If yes, why? and how can i pass value between one page and the other without
using the url?


Feel free to do that if you wish. It will only exist until the end of
this script though.

To pass variables between scripts you can do one of the following:
1. Add them to the URL and pick from $HTTP_GET_VARS (now $_GET)
2. Add them to a form and pick from $HTTP_POST_VARS (now $_POST)
3. add them to $_SESSION[] which is probably the recommended way.

Jul 17 '05 #2
Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS

$HTTP_GET_VARS['foo'] = 'bar'?
If yes, why? and how can i pass value between one page and the other without using the url?
Feel free to do that if you wish. It will only exist until the end of
this script though.


Yes sorry that is what i should have said.
if( !$HTTP_GET_VARS['foo'] ){
$HTTP_GET_VARS['foo'] = 'bar';
}
....

it would make it easier for me to assume that $HTTP_GET_VARS['foo'] exists
by forcefully setting it at the beginning of the script.
There are many ways of doing it like

$myscritval['foo'] = isset(
$_GET['foo'])?$_GET['foo']:(isset($_POST['foo'])?$_POST['foo']:'bar';

I was curious about the value of $HTTP_GET_VARS if it was bad practice to
set that value.

To pass variables between scripts you can do one of the following:
1. Add them to the URL and pick from $HTTP_GET_VARS (now $_GET)
2. Add them to a form and pick from $HTTP_POST_VARS (now $_POST)
What is the minimum php version for $_GET and $POST? I was told to use the
old version as it will not hurt my script, ( as long as i have global
$HTTP_GET_VARS; in my functions).
3. add them to $_SESSION[] which is probably the recommended way.


Yes of course, that is another way. But i keep been told that there are
times where the user can set his browser to make sessions useless.
But i have never really looked into it really.

Sims
Jul 17 '05 #3
Sims wrote:
Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARS
Feel free to do that if you wish. It will only exist until the end of
this script though.

Yes sorry that is what i should have said.
if( !$HTTP_GET_VARS['foo'] ){
$HTTP_GET_VARS['foo'] = 'bar';
}
...

it would make it easier for me to assume that $HTTP_GET_VARS['foo'] exists
by forcefully setting it at the beginning of the script.


Absolutely fine. That's probably good practice, while you're at it you
should check that the sent value is reasonable.
What is the minimum php version for $_GET and $POST? I was told to use the
old version as it will not hurt my script, ( as long as i have global
$HTTP_GET_VARS; in my functions).
4.1.0 - you'll need to watch out though as later releases of php will do
away with the old variables.
3. add them to $_SESSION[] which is probably the recommended way.


Yes of course, that is another way. But i keep been told that there are
times where the user can set his browser to make sessions useless.
But i have never really looked into it really.


Sessions are really aimed towards using cookies. If cookie support is
turned off then they don't work properly. There is a php.ini setting to
transparently test if cookies are available and default to modifying all
links to add the session id. It doesn't look pretty if cookies are off
though.
Jul 17 '05 #4
"Kevin Thorpe" <ke***@pricetrak.com> schrieb im Newsbeitrag
news:40**********************@news.easynet.co.uk.. .
Sims wrote:
Is it wrong to forcefully set a value HTTP_GET_VARS and HTTP_POST_VARSFeel free to do that if you wish. It will only exist until the end of
this script though.

Yes sorry that is what i should have said.
if( !$HTTP_GET_VARS['foo'] ){
$HTTP_GET_VARS['foo'] = 'bar';
}
...

it would make it easier for me to assume that $HTTP_GET_VARS['foo'] exists by forcefully setting it at the beginning of the script.


Absolutely fine. That's probably good practice, while you're at it you
should check that the sent value is reasonable.


It seems wrong to me to create a variable that looks like a get variable but
is none. Why not:

if(isset($_GET['foo'])) {
$foo = $_GET['foo'];
}
else {
$foo = "bar";
}

If you extract all your request variables like that before processing them
you have a transparent code. (If $foo can be transmitted with either get or
post, just check for $_REQUEST['foo']). Also it is easier to write $foo than
$_GET['foo'] or even $HTTP_GET_VARS['foo'] all the time.

Imagine your script is 400 lines long, and anywhere your above code appears.
In 2 years you have to make a modification, it will take you an hour to
figure out why there is a value for a field that you did not submit!

HTH
Markus
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ben Hall | last post by:
Hey guys, I'm building a web application in php for the first time (I like php a lot..) and have come across a litle stumbling block. I want to access a passed url parameter with...
5
by: Phrylock | last post by:
I am a beggining PHP developer (been doing it for like 3 weeks now) and I am currently having a problem getting these arrays to work. I am running PHP 4.3.4 with Apache 2.0.47 on WinXP. I have a...
2
by: John Pastrovick | last post by:
I am new to PHP, coming from ASP coding if (HTTP_GET_VARS==1){ print "Yes"; }else{ print "No"; } when "b" is not passed via (http://www.mydomain.com?b=1
1
by: Chris Cox | last post by:
Hi, Hoping someone can help, I have a sql query which is passed to the script via the url, this is like:- &stmt=select%20*%20from%20table%20where%20(%20status!='Closed'%20..... If I look at...
6
by: Niyazi | last post by:
Hi, We have and IBM AS400 and I belive the reional setting is Turkish. The IBM Client-Access for Windows that install in our PC (WIN XP SP2) set to Turkish characters. Now my PC has English...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
0
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not...
2
by: junlia | last post by:
Hi All, I am working on a project that acts as a bridge. It does some checking with post xml data, and then redirects the request to an appropriate page. However, we find that depends on the...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
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,...
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
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,...
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,...
0
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...

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.