473,545 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

after moving to new server, variables in query string notinstantiated ?

I'm moving a bunch of PHP scripts from a server where they ran on
PHP4, to a new server with PHP5.

On the old server, variables in the query string would be
automatically instantiated in the code, so for example with this PHP
code:
<?php
print "Username: $username";
?>

accessing this URL would print the username "bennett":
http://69.20.9.236/php/test2.php?username=bennett

However, on the new server, it does not:
http://12.47.46.159/php/test2.php?username=bennett

Is this something that changed between PHP 4 and 5? I couldn't find
anything about this listed in the "What's new in PHP 5" at
http://devzone.zend.com/node/view/id/1714

The output of phpinfo() on the two servers is:
http://69.20.9.236/php/showall.php
http://12.47.46.159/php/showall.php

Is there some simple change that I can make, that will enable all of
the old PHP scripts to work on the new server? I'm really hoping the
latest version of PHP didn't force everyone to rewrite scripts that
used the old behavior.

-Bennett
Aug 5 '08 #1
14 1818
smells like register_global s are off and yes they are.
add $username = $_GET['username'];

Aug 5 '08 #2
On Aug 5, 5:09*pm, The Hajj <hajji.hims...@ gmail.comwrote:
smells like register_global s are off and yes they are.

add $username = $_GET['username'];
forgot to add, if you're doing stuff like that filter input(good idear
to filter input anyways)
Aug 5 '08 #3
Bennett Haselton wrote:
I'm moving a bunch of PHP scripts from a server where they ran on
PHP4, to a new server with PHP5.

On the old server, variables in the query string would be
automatically instantiated in the code, so for example with this PHP
code:
<?php
print "Username: $username";
?>

accessing this URL would print the username "bennett":
http://69.20.9.236/php/test2.php?username=bennett

However, on the new server, it does not:
http://12.47.46.159/php/test2.php?username=bennett

Is this something that changed between PHP 4 and 5? I couldn't find
anything about this listed in the "What's new in PHP 5" at
http://devzone.zend.com/node/view/id/1714

The output of phpinfo() on the two servers is:
http://69.20.9.236/php/showall.php
http://12.47.46.159/php/showall.php

Is there some simple change that I can make, that will enable all of
the old PHP scripts to work on the new server? I'm really hoping the
latest version of PHP didn't force everyone to rewrite scripts that
used the old behavior.

-Bennett
Your PHP 4 operation was caused by register_global s being on in the
php.ini file. You can turn it on in PHP5 - but you need to start
converting your scripts now.

This can be a big security risk, and the option will be removed
completely in PHP 6.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 5 '08 #4
Looks like you might have had register globals on on the old server,
did you code in
$username = $_GET['username'];
or similar before your example line- If not, then you had Register
Globals On, which is a bad thing. R.G. may be convenient but it also
opens you up to a bunch of security issues.

My suggestion is to at least put in the $_GET[] lines in the beginning
to read in the data. ( $username = $_GET['username']; ) Or better
write some sanitizing functions in your common function library like:
// Process a $_GET Value
function readGet($item) {
$value = '';
if( isset($_GET[$item])) {
$value = $_GET[$item];
$value = cleanValue($val ue);
return $value;
}
}

// Sanitize foreign data - only allow what is needed (use this where
needed, reading GETs, POSTs, COOKIEs or foreign DB/file data.)

function cleanValue($str ing) {
$string = preg_replace( '/[^a-zA-Z0-9$,.:+?%\(\)\/\'@"\-_\s]/',
'', $string );
return $string;
}

Then in your code you would use

$username = readGet('userna me');

Which is way more secure (at least if it were displayed; though if it
references a file name or is part of a DB query or content then you
may want to read more on PHP security.)

This is a great start:
http://www.sitepoint.com/article/php-security-blunders

Good Luck
Aug 5 '08 #5
never heard of readGet(), google looks at me like I'm stupid

Aug 5 '08 #6
The Hajj wrote:
never heard of readGet(), google looks at me like I'm stupid

It's a function Larry gave you in his code. It's OK to use that if
that's the filtering you need (not everything should be filtered the
same way - i.e. numerics should be handled as numerics).

But at the very least you should test to ensure the array element is
set, i.e.

$username = isset($_GET['username']) ? $_GET['username'] : '';

The '' at the end can be replaced by null or any other default value you
want.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Aug 5 '08 #7
On Aug 5, 6:46*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
The Hajj wrote:
never heard of readGet(), google looks at me like I'm stupid

It's a function Larry gave you in his code. *It's OK to use that if
that's the filtering you need (not everything should be filtered the
same way - i.e. numerics should be handled as numerics).
DOH!! Google was right! Dern Javascript is converting me to the dark
side. And good gawd I've got to finish reading Mastering regular
expressions. I think it would have been easier to tell him to use
$username = strip_tags($_GE T['username']);
Aug 5 '08 #8
The Hajj wrote:
On Aug 5, 6:46 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>The Hajj wrote:
>>never heard of readGet(), google looks at me like I'm stupid
It's a function Larry gave you in his code. It's OK to use that if
that's the filtering you need (not everything should be filtered the
same way - i.e. numerics should be handled as numerics).

DOH!! Google was right! Dern Javascript is converting me to the dark
side. And good gawd I've got to finish reading Mastering regular
expressions. I think it would have been easier to tell him to use
$username = strip_tags($_GE T['username']);
Which will give you an E_NOTICE if there is no 'username' element of the
$_GET array (hence the isset() call).

And while this will limit PHP insertion, it may not be what you want.
Better would be to use a regex or similar to check for invalid
characters in the username.

Also, you really DON'T want to change the data coming in - just accept
it or reject it. Otherwise the use may think he's using one username
when he's really gotten another.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 5 '08 #9
Ah yes the regular expression(as simple as it is!) makes sense now,
notices no < {} [] & etc I've forgotten all about
E_NOTICE(Javasc ript'n lately!). I've been getting use to change data
as I deal with alot of forms and processing user junk so that didn't
even come to mind.

Aug 5 '08 #10

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

Similar topics

13
2868
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine. Value selected is used as the 'where' clause of the 2nd query. If $site is a single word, the 2nd query works like a charm. If $site is more than one...
4
1870
by: Mullin Yu | last post by:
i have a stored procedure at sql server 2k. which will update records and select result from temp table. if i use SqlConnection class, and i do both. but, if i use OleDbConnection class, i can have only records updated, but no result come out. how can i debug, and what's the error? thanks!
2
1593
by: James Wallace | last post by:
I hope that someone can help me out there with this problem. I get an itermittant problem with our web page that occurs about once every 10 to 15 days where the only way to fix the problem is to bounce the web server. The error can be seen below. I have looked at the stack trace and determined where the error is occuring but when I look...
3
1128
by: Geoff | last post by:
All my pages come up with "SQL Server does not exist or access denied" after moving to a new Sql Server with a different name. None of my pages come up even though I am addressing the servername by IP Address. I can access the Server through Enterprise Manager and Query Analyzer using the same IP. I've also made sure the changes were made in...
1
2005
by: Rico | last post by:
I have tried to access a database using asp.net. after some entries like 120+, I got an unspecified error message. Anyone know what is happening, it seems to be stuck at the same line even when i added a new line. Here is the error message: Server Error in '/sonamy' Application....
0
2003
by: xkp | last post by:
i am having problems with this query which worked perfrcly on mysql 3.0. It is able to extract dowloaders from a table and group them by date. select count(*) AS downloaders, date_format(date,'%Y-%m-%d') AS Datesmall, date_format(date,'%D %M %Y') AS Date from downloaders Group By date_format(date,'%D %M %Y ') order by...
3
1627
by: Don Miller | last post by:
In my migration from ASP to ASP.NET 2.0, I have a fair number of complicated HTML tables that defy anything .NET can do. Using classic ASP I created these tables (by string concatenation) by moving forward, and at times, backward through a recordset (using a static cursor rather than a forward-only cursor). I can't seem to find any methods...
7
10809
by: =?Utf-8?B?TW9iaWxlTWFu?= | last post by:
Hello everyone: I am looking for everyone's thoughts on moving large amounts (actually, not very large, but large enough that I'm throwing exceptions using the default configurations). We're doing a proof-of-concept on WCF whereby we have a Windows form client and a Server. Our server is a middle-tier that interfaces with our SQL 05...
0
4627
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars (double) Sales Units (double) Promo (Text) -- is null or "X" AvgWklyDollars (double) AvgWklyUnits (double) I have a vba module which I thought would...
0
7468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7808
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7423
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5329
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1884
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 we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.