473,494 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

changing old script - register globals - how to convert?

this old script was written when

register globals was 'on'.

now i need to convert it to run on a server with a php 4.3.6 - do i just
convert the relevant variables from

$posted_variable to $_POST['posted_variable']

i realise that many of the variables are internal to the scrit so will not
be altered.

i'm slightly concerned because some of the script refers to variables which
are used as streams and used to upload image files.

thanks for any pointers,

kev


here are the scripts from
http://www.onlamp.com/pub/a/onlamp/2...b2.html?page=1

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Browse Upload Files</title>
</head>
<body bgcolor="white">

<?php
include 'db.inc';

$query = "SELECT id, shortName, mimeName FROM files";

if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();

if (!mysql_select_db("files", $connection))
showerror();

if (!($result = @ mysql_query ($query, $connection)))
showerror();
?>
<h1>Image database</h1>

<h3>Click <a href="insert.php">here</a> to
upload an image.</h3>
<?php
require 'disclaimer';

if ($row = @ mysql_fetch_array($result))
{
?>

<table>
<col span="1" align="right">
<tr>
<th>Short description</th>
<th>File type</th>
<th>Image</th>

</tr>
<?php
do
{
?>
<tr>
<td><?php echo "{$row["shortName"]}";?></td>
<td><?php echo "{$row["mimeName"]}";?></td>
<td><?php echo "<img src=\"view.php?file={$row["id"]}\">";?></td>
</tr>
<?php
} while ($row = @ mysql_fetch_array($result));
?>
</table>
<?php
} // if mysql_fetch_array()
else
echo "<h3>There are no images to display</h3>\n";
?>
</body>
</html>
Jul 17 '05 #1
12 2659
kevin bailey wrote:
this old script was written when

register globals was 'on'.

now i need to convert it to run on a server with a php 4.3.6 - do i just
convert the relevant variables from

$posted_variable to $_POST['posted_variable']


In general, you cannot assume this. If you don't fully understand where
variable names are coming from, it is safer to use $_REQUEST, which
combines $_GET, $_POST, and $_COOKIES. In addition, if the scripts used
sessions, you may have to use $_SESSION.

More detail here:
http://us2.php.net/manual/en/languag...predefined.php

Gunter
Jul 17 '05 #2
Yes, using $_POST will get the posted arrays into the variable, you can
also use $_REQUEST to get either POST or GET variables. But just make
sure you set them to null first..

$var = "";
if(isset($_POST['var'])) $var = $_POST['var'];
otherwise if you try to use $var it will return a warning.

Jul 17 '05 #3
.oO(jblanch)
Yes, using $_POST will get the posted arrays into the variable, you can
also use $_REQUEST to get either POST or GET variables. But just make
sure you set them to null first..
Not necessary in this case:
$var = "";
if(isset($_POST['var'])) $var = $_POST['var'];
otherwise if you try to use $var it will return a warning.


PHP will show a notice if you try to read an uninitialized variable, but
the above is an assignment. You don't have to initialize $var with an
empty string in this case.

Micha
Jul 17 '05 #4
But you need to assign the varibles to the posted variables without
register globals on, correct? I'm not quite sure where his varibles
are, but i assumed that there are others in differen't scripts that are
more obious, i'm assuming that you have somthing from a form, like
<input type="text" name="username"> and you are reading it to login a
user or somthing of the like, in which case you need to assign the
varibles using the $_POST Global variable array.

Jul 17 '05 #5
But you need to assign the varibles to the posted variables without
register globals on, correct? I'm not quite sure where his varibles
are, but i assumed that there are others in differen't scripts that are
more obious, i'm assuming that you have somthing from a form, like
<input type="text" name="username"> and you are reading it to login a
user or somthing of the like, in which case you need to assign the
varibles using the $_POST Global variable array.

Jul 17 '05 #6
jblanch wrote:
But you need to assign the varibles to the posted variables without
register globals on, correct? I'm not quite sure where his varibles
are, but i assumed that there are others in differen't scripts that are
more obious, i'm assuming that you have somthing from a form, like
<input type="text" name="username"> and you are reading it to login a
user or somthing of the like, in which case you need to assign the
varibles using the $_POST Global variable array.


yep - it is really only the $_POST variables which i need.

thanks for the replies,

kev
Jul 17 '05 #7
On 30 Jan 2005 17:00:30 -0800, jblanch wrote:
Yes, using $_POST will get the posted arrays into the variable, you can
also use $_REQUEST to get either POST or GET variables. But just make
sure you set them to null first..

$var = "";
if(isset($_POST['var'])) $var = $_POST['var'];
otherwise if you try to use $var it will return a warning.


You could use:

$var = isset($_POST['var']) ? $_POST['var'] : '';

This will set $var to the value of $_POST['var'] if it's set and to ''
if not.

--
Regards - Rodney Pont
The from address exists but is mostly dumped,
please send any emails to the address below
e-mail ngpsm4 (at) infohitsystems (dot) ltd (dot) uk
Jul 17 '05 #8
kevin bailey <kb*****@freewayprojects.com> writes:
this old script was written when

register globals was 'on'.

now i need to convert it to run on a server with a php 4.3.6 - do i just
convert the relevant variables from


Could be a lot of work. Depends on the complexity of the code that
you need to convert and of course, how many scripts there are.

Why don't you reenable register_globals in the .htaccess file and get
on with your life?

HTH

--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #9
kevin bailey <kb*****@freewayprojects.com> writes:
yep - it is really only the $_POST variables which i need.


how about;

extract($_POST); # done right at the top of your scripts?

--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #10
.oO(jblanch)
But you need to assign the varibles to the posted variables without
register globals on, correct? I'm not quite sure where his varibles
are, but i assumed that there are others in differen't scripts that are
more obious, i'm assuming that you have somthing from a form, like
<input type="text" name="username"> and you are reading it to login a
user or somthing of the like, in which case you need to assign the
varibles using the $_POST Global variable array.


OK, forget my previous posting, I missed something (the default value of
$var in case $_POST['var'] doesn't exist). Your script was correct.

Micha
Jul 17 '05 #11
"kevin bailey" <kb*****@freewayprojects.com> wrote in message
news:ct*******************@news.demon.co.uk...
this old script was written when

register globals was 'on'.

now i need to convert it to run on a server with a php 4.3.6 - do i just
convert the relevant variables from

$posted_variable to $_POST['posted_variable']

i realise that many of the variables are internal to the scrit so will not
be altered.

i'm slightly concerned because some of the script refers to variables which are used as streams and used to upload image files.

thanks for any pointers,

kev


Just stick a extract($_REQUEST) in a globally included file.
Jul 17 '05 #12
Jerry Sievers wrote:
kevin bailey <kb*****@freewayprojects.com> writes:
yep - it is really only the $_POST variables which i need.


how about;

extract($_POST); # done right at the top of your scripts?

thanks - i'll check it out
Jul 17 '05 #13

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

Similar topics

2
1886
by: ˝Viking˝ | last post by:
The server that the script will run on has the following settings: PHP Ver: 4.1.2 Server API: CGI Register Globals: ON Session Support: ON I want to use sessions to store the information...
3
2833
by: koolyio | last post by:
Hey, could you please tell me what is wrong with my login script. I just started learning php. CODE: login.php <? session_start(); header("Cache-Control: private"); ?>
0
1579
by: infinull | last post by:
I am making a script that is a very complex Content Management system. it makes a UDM navigation bar and writes content and a title. i want it to write content other that just basic text, like a...
8
3345
by: jasonbrown1999 | last post by:
Someone told me the following script could be used to run harmful commands on the server, by passing commands into the script. What the script does is encode an affiliate URL, create two frames,...
1
1802
by: yawnmoth | last post by:
even though register globals is disabled by default, i'm currious as to how it and magic quotes interact. consider the following code: <? // assuming $_GET='"test"' and register globals enabled...
1
1745
by: viktor9990 | last post by:
I have a page called CustomerSlides.aspx which contains an iframe(with the source Lookupage.aspx). The iframe page will look continuously in the database to see if a value has changed: if it is...
1
1780
by: viktor9990 | last post by:
I have a page called CustomerSlides.aspx which contains an iframe(with the source Lookupage.aspx). The iframe page will look continuously in the database to see if a value has changed: if it is...
7
1441
by: Minnie | last post by:
Hi everyone, I was trying to use a script called PHPrint, but I think the reason it's not working is because I have register globals off. This decision is not under my control, and I am not...
3
3057
by: shybe | last post by:
Ok, Im trying to create a "send this article to a friend" script for my blog, Right now its sending all the articles, but I want it to only send the article in which the form is attached...
0
7119
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
6989
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
7157
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
7195
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...
1
6873
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...
0
7367
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
5453
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,...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
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...

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.