By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,883 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

changing old script - register globals - how to convert?

P: n/a
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
Share this Question
Share on Google+
12 Replies


P: n/a
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

P: n/a
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

P: n/a
.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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
.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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.