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

Disabling global vars without php.ini access?

I've got a server where register_globals is on in php.ini, but its affecting
the way the website works. It was programmed with the assumption that it
would always be off, and i've always used the full names such as
$_SESSION['userid'] etc in all the code. However, I also use some local
variables of $userid, and on this server they seem to be changing the
session variable when I use them. I don't have access to php.ini, and its
on a Win2000 server so can't use htaccess. According to the documentation,
I can't set it at runtime with ini_set.

So, is there any way I can disable the operation of register globals /
superglobal variables in this situation? I really don't want to go through
and change all my variable names, since that is exactly why I made sure to
use the full variable name every time for sessions, post and get values.
Thanks

David
Jul 17 '05 #1
7 6431
"David Walker" a écrit le 05/11/2003 :
I've got a server where register_globals is on in php.ini, but its affecting
the way the website works. It was programmed with the assumption that it
would always be off, and i've always used the full names such as
$_SESSION['userid'] etc in all the code. However, I also use some local
variables of $userid, and on this server they seem to be changing the
session variable when I use them. I don't have access to php.ini, and its
on a Win2000 server so can't use htaccess. According to the documentation,
I can't set it at runtime with ini_set.

So, is there any way I can disable the operation of register globals /
superglobal variables in this situation? I really don't want to go through
and change all my variable names, since that is exactly why I made sure to
use the full variable name every time for sessions, post and get values.
Thanks

David


Maybe you could try to browse through the $_POST, $_GET and $_COOKIE
vars and unset the correspondant var at the beginning of your scripts :

foreach( $_POST AS $key => $val )
{
unset $$key;
}

Without any warranty, not tried.
Jul 17 '05 #2
> Maybe you could try to browse through the $_POST, $_GET and $_COOKIE
vars and unset the correspondant var at the beginning of your scripts :

foreach( $_POST AS $key => $val )
{
unset $$key;
}


I still want to be able to access those variables though. For example, the
userid variable I have.

Pages on the site with restricted access check that value as a session
variable, as $_SESSION['userid'], but on a page like that I may be changing
someone elses details, for which I use the local variable $userid. I want
to be able to use both separately on the same page.
I'd hoped for another way to disable global_variables without php.ini
access.

David
Jul 17 '05 #3
David Walker wrote:
Maybe you could try to browse through the $_POST, $_GET and $_COOKIE
vars and unset the correspondant var at the beginning of your scripts :

foreach( $_POST AS $key => $val )
{
unset $$key;
}

I still want to be able to access those variables though. For example, the
userid variable I have.

Pages on the site with restricted access check that value as a session
variable, as $_SESSION['userid'], but on a page like that I may be changing
someone elses details, for which I use the local variable $userid. I want
to be able to use both separately on the same page.
I'd hoped for another way to disable global_variables without php.ini
access.

David


No, he didn't mean you unset them from the superglobal arrays, he meant
the CORRESPONDING variables (symbols).

ie.

foreach($_REQUEST as $varName => $varVal) unset($varName);

notice that $_REQUEST is *still populated*. $_REQUEST includes $_GET,
$_POST, $_COOKIE (GPC). You need another foreach statement to take care
of $_SESSION

foreach($_SESSION as $varName => $varVal) @unset($varName);

stick that (both lines) at the top of your pages.

Jul 17 '05 #4
"David Walker" <wb*********@hotmail.com> wrote in message news:<bo**********@wisteria.csv.warwick.ac.uk>...
I've got a server where register_globals is on in php.ini, but its affecting
the way the website works. It was programmed with the assumption that it
would always be off, and i've always used the full names such as
$_SESSION['userid'] etc in all the code. However, I also use some local
variables of $userid, and on this server they seem to be changing the
session variable when I use them.


Is it the problem that I reported once? (
http://bugs.php.net/bug.php?id=22389 )
---
"The world is too dangerous to live in—not because of the people who
do evil, but because of the people who sit and let it happen"---Albert
Einstein
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5
> No, he didn't mean you unset them from the superglobal arrays, he meant
the CORRESPONDING variables (symbols).
ie.
foreach($_REQUEST as $varName => $varVal) unset($varName);


Ahh yeah - I see what you mean now *it all clicks into place*
I'll give it a go when I get back in tonight, see what happens.

Thanks

David
Jul 17 '05 #6
> Is it the problem that I reported once? (
http://bugs.php.net/bug.php?id=22389 )


Yeah, sounds the same - just confirms that i'll probably just have to change
all my variable names! :o(

David
Jul 17 '05 #7
"David Walker" <wb*********@hotmail.com> wrote in message news:<bo**********@wisteria.csv.warwick.ac.uk>...
Is it the problem that I reported once? (
http://bugs.php.net/bug.php?id=22389 )


Yeah, sounds the same - just confirms that i'll probably just have to change
all my variable names! :o(


AFAIK, it is true for 4.3.0. IIRC, it has been fixed in 4.3.2.
So, try to upgrage your PHP.

---
"Learn from yesterday, live for today, hope for tomorrow. The
important thing is to not stop questioning."---Albert Einstein
Email: rrjanbiah-at-Y!com
Jul 17 '05 #8

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

Similar topics

14
by: lkrubner | last post by:
If I set a variable at the top of my code like this: $name = "Lawrence"; It is now a global variable. If, later on, in a function, I want to do this: function uppercaseName() { global...
0
by: Kepes Krisztian | last post by:
Hi ! How to access my module global vars ? Some applications I want to declare global vars (constants). But in the module I cannot access them: DEF_X=120
0
by: Christopher J. Bottaro | last post by:
>From the python programming FAQ, I learned you can do this: Globals.py: gv = 1 A.py: import Globals class A: def __init__(self): print Globals.gv
6
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following...
4
by: Kenny Ashton | last post by:
Hello gurus Can I ask you opions on the best compromise for storing Access Ado connection strings in a IIS4 standard ASP environment. For any method I use, there seems to be an article somewhere...
16
by: WaterBug | last post by:
When clicking on the following link from an email i.e - http://myserver/myapplication/myprogram.asp?urlvar1=some%20stuff&urlvar2=more%20stuff I get a server 500 error. With that same browser...
10
by: Kleenex | last post by:
Reason: I am working on an embedded project which has very limited memory (under 512 bytes, 60 or so of which is stack space), which translates into limited stack space. In order to save on stack...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
0
by: Gary Herron | last post by:
Jacob Davis wrote: Yuck, YUCK, YUCK! You are breaking *so* many good-programming-practices, I hardly know where to start. First off: A python global is not what you think. There are *no*...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.