473,473 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to remove register_globals dependency from my code?

117 New Member
As i posted before i started this project on a premade script from a uk site a year back but i never knew at that time after 5000000000 hours of hard work and now ppl tell me it was bad to use RG...

So i need an experts help removing the requirement for it, and i know ask the maker his site is gone and host banned... :( So i am all alone here....

I made a zip file with all the files backend files (commen,proccess) and i can send it to anyone willing to help me.
I have no clue where to start.. I just want evil php troll dead...
Sep 26 '07 #1
6 3027
Atli
5,058 Recognized Expert Expert
Hi Breana.

What you need to do is find all variables in your scripts that belong to one of the super-globals and exchange them for their respective element in the super-global arrays.

If that doesn't make sense (which is likely given my lack of sleep lately) perhaps this will make more sence:

Lets say that you are accepting a user-name and a password from a HTML form. If your code assumes that the register_globals constant is enabled, it may look like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($formSubmit)) {
  3.   # Print the user
  4.   echo "<b>You sent this info!</b><br />"
  5.   echo "Username: $username<br />Password: $password";
  6. }
  7. ?>
  8. <form action="?" method="post">
  9.   <input type="text" name="username" /><br />
  10.   <input type="password" name="password" /><br />
  11.   <input type="submit" name="formSubmit" />
  12. </form>
  13.  
To free this code from it's dependency on register_globals, you could to this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['formSubmit'])) {
  3.   $username = $_POST['username'];
  4.   $password = $_POST['password'];
  5.  
  6.   # Print the user
  7.   echo "<b>You sent this info!</b><br />"
  8.   echo "Username: $username<br />Password: $password";
  9. }
  10. ?>
  11. <form action="?" method="post">
  12.   <input type="text" name="username" /><br />
  13.   <input type="password" name="password" /><br />
  14.   <input type="submit" name="formSubmit" />
  15. </form>
  16.  
I've skipped all validation, as this is just an example, but in a live code you should validate the user input before printing it!
Sep 27 '07 #2
Breana
117 New Member
I am kind of lost, do i need to remove the session and "$_REQUEST['login']" too. I dont under stand this at all. I am trying to learn here but this is bizzar to me..

This is what i came up with hope i understood u :)
[PHP]<?
if(isset($_POST['formSubmit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "select * from users where login = '$login' and password = '" . sha1($password) . "'";
$result = mysql_query($sql ,$db);
if ($myrow = mysql_fetch_array($result)) {

do {

$uid = $myrow["userid"];
$uname = $myrow["login"];

} while ($myrow = mysql_fetch_array($result));

$loggedin = true;
$upwd = $password;
echo 'session_register("loggedin")';

session_register("upwd");
session_register("uid");
session_register("uname");
//Print the user
echo "<p align='center'><font size='2' face='Arial'><br />
<b>Welcome back</b>, You will be redirected in <font color='#FF0000'>3</font> seconds!<br />
<br />
<img src='images/ajax_loading.gif' alt='Loading' width='32' height='32' /><br />
<br />
Or <a href='index.php'>Click here</a> if you don't want to wait!</font></p>"
echo "Username: $username<br />Password: $password";
} else {
$loggedin = false;
$upwd = "";
$uid = "";
$uname = "";
echo "<img src='images/invalid.gif' width='402' height='107' /><br /><b><font color='#FF0000'>Sorry,</font></b> that ID or Password is not valid.<br /><br /><br />If you have forgotten your password <a href='forgot.php'>Reset Password</a>. <br />If you are a new user you will need to <a href='newuser.php'>Create A New Account!</a>";

}
?>[/PHP]
Sep 27 '07 #3
Atli
5,058 Recognized Expert Expert
That code looks fine. Shouldn't have any problems with register_globals disabled.

The register_globals constant, when enabled, basically does exactly what this code does:
Expand|Select|Wrap|Line Numbers
  1. # The order of this may vary
  2. extract($_REQUEST, EXTR_OVERWRITE);
  3. extract($_SESSION, EXTR_OVERWRITE);
  4.  
This basically takes all elements from those arrays and imports them into the global scope, making them available as regular variables rather than array elements.

For example:
Expand|Select|Wrap|Line Numbers
  1. # If register_globals is enabled this:
  2. echo $_POST['myFormInput'];
  3.  
  4. # can also be accessed like this:
  5. echo $myFormInput; 
  6.  
  7. # They are one and the same thing
  8.  
Which is a very bad thing, as PHP is creating extra variables in the global scope that have not been verified and may never even be used.
Not to mention that if an element in one of the super-global arrays has the same name as an element in one of the other super-globals, only one of them can be extracted as a variable, which can easily cause problems.

So, by disabling the register_global directive, PHP will no longer creating these extra variables in the global scope, which makes your code more secure as well as boosting performance.
Sep 27 '07 #4
Atli
5,058 Recognized Expert Expert
I've re-phrased the title of this thread to make it a little clearer.
Please do not use phrases like 'need help' in thread titles.
Check out the Posting guidelines for tips on how to create good thread titles.

Moderator
Sep 27 '07 #5
Breana
117 New Member
Nope... it dont work.
Wont validate the user... keeps saying badlogin on a good id + pass

I am just going to search for a pre made cheatcode cms and use it.
If anyone here knows of a good free one im me please. :(
Sep 27 '07 #6
Atli
5,058 Recognized Expert Expert
Nope... it dont work.
Wont validate the user... keeps saying badlogin on a good id + pass

I am just going to search for a pre made cheatcode cms and use it.
If anyone here knows of a good free one im me please. :(
Sorry to hear that.
Before you give up on your script, did you echo the contents of the $_POST array? Was there any data?
This could be something simple as magic_quotes_gpc being enabled an adding extra quote marks to your variables.
Sep 28 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Frank | last post by:
Whats best : register_globals ON ? OR register_globals OFF ? I currently use: $_POST
5
by: ChronicFatigue | last post by:
Hello My current host has register_globals switched on in their php.ini file. Would it be prudent for me to design code which works when register_globals is switched off in case I switch hosts...
10
by: John | last post by:
Hello. I am a newbie to PHP. I am over halfway through my first book that I'm learning with and have just created login pages etc. I just wondered, if I am running php/mysql/apache locally,...
6
by: wonder | last post by:
Hi, The CRM application said that need to add an option "REGISTER_GLOBALS=On" to the php.ini file, so I did what it told. But I still can't get rid off the following error: The PHP variable...
8
by: lian | last post by:
Hi all, I have installed a web-based software written in php which needs that i should turn "register_globals" from off to on in the php.ini. There are some comments for register_globals in...
15
by: news | last post by:
You'd think it'd be easier to find the answer to this question. Did a search, and all I can find is people asking why something's not working and people replying it's because register_globals is...
6
by: peter | last post by:
Hi. I am just learning PHP. I'm taking over the website at work, which is coded in PHP. I am wondering about register_globals. They are on on the server we use. Is that a threat? I understand...
17
by: peter | last post by:
I just took over the website at work. I am still learning PHP. Register_globals are on and the script appears to be coded to take advantage of this. I know how to recode the script, but am unsure...
1
by: vincentt | last post by:
Hi, We code DLL's and so far it was done using VS6.0. We are planning to migrate the VS.NET 2005 and use the VS6 VC++ code which generated the DLL to VS 2005 VC++.NET. However we donot plan to...
8
by: +mrcakey | last post by:
I understand that register_globals was turned off by default as, unless you initialised it, it could be altered by a malicious coder. What I don't understand is how the $_POST form is any more...
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
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
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.