[SOLVED] Post vars

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

[SOLVED] Post vars

Post by oldtimer »

I am doing work on some pages on a server that is php 4.0.6 and mine is 4.1.2. On my server i can go $_POST[value] on theirs it will not work. Neither will adding a ' or a " around value. I can however do $HTTP_POST_VARS[value]. What can I tell this person to do to make it so that the $_POST works?

Help is appreciated.
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

Ooooo I know this one... I have servers of same spec... it's annoying ain't it...

Ok, several questions:

1) Do you admin the server... ie do you have access to the php.ini file?

2) is the an standard include file that is included in all of their scripts... if so try:

Code: Select all

<?php $_POST = $HTTP_POST_VARS; ?>
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

1) No I dont have access but the admin does and he will try what I suggest.

2) Not sure what you mean there.
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

Ok, well the php.ini file edit of auto_prepend is out if u don't have access to thephp.ini file... oh well...


What I meant be no. 2 is....

I have scipts in a web site that ALL include a series of standard files, such as:
initialise.php - contains all the initialisation of sessions, cookies, variables, db connections etc.
header.php - contains the header for the html
footer.php - need i explain


initialise.php is included at the begining of every script in my site, so a skeletal page would look a bit like:

Code: Select all

<?php
require_once $HTTP_SERVER_VARS["DOCUMENT_ROOT"]."/include/initialise.php";
require_once $HTTP_SERVER_VARS["DOCUMENT_ROOT"]."/include/footer.php";

// ALL code goes here

require_once $HTTP_SERVER_VARS["DOCUMENT_ROOT"]."/include/footer.php";
?>
So if you had any files like that then you could just make the first line the statement I mention above
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

Okay I see what you mean. where as i include a config file on every page I could have the $_POST = $HTTP_POST_VARS; in that as well. That would work great. First I will have the person edit their php.ini file first. I know he will want to get it to where just the _Post works.
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

What would I edit in the php.ini. I just got access to it.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Your problem is not an ini configuration; rather the server version.

$_POST was added to PHP in 4.1.0.

http://www.php.net/manual/en/reserved.v ... ables.post
HTTP POST variables: $_POST
Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS.

An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS.

$HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_POST and $HTTP_POST_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
I suggest telling the server admin to upgrade to a newer version.
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

Thank you. Now we just need to see if he can safely upgrade and not mess up his Cobalt 550 :) I will get this information to him.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

No problem. Good luck with that! :)
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

.... Hoever, if you cannot update (what with it being a cobalt and all) what I was hinting at with the php.ini file is the 'auto_prepend_file =' line

You need to set this as a file that contains the above code.

If however, you can upgrade php then great, wish all of us where that lucky!
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

Ahh. so i change this line.

Code: Select all

auto_prepend_file	=
to

Code: Select all

auto_prepend_file	= $_POST = $HTTP_POST_VARS;
??
I do have access to the file and I can add anything that needs to be added.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I believe that ini setting includes a file within all the pages on the server.

It's been a while since I used it and I can't find info within the manual about it. I might be a bit off with the info below...

So auto_prepend_file = /postvarsupdate.php would fix your problem if that page contained something like this:

Code: Select all

<?php
$_POST = $HTTP_POST_VARS
?>
As is says in the quote above; "You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS."

Wouldn't that cause some issues with scripts that don't use global $_POST; or global $HTTP_POST_VARS; after a function definition? I'd guess so.
Post Reply