Jump to content

PHP 5.5 transition


wkilc

Recommended Posts

Hi all,

 

I am a PHP novice.  I use a script on my site to display multiple table rows with alternating colors and what I believe is called "pagation".  (Takes 1,500 rows and displays only 25 or 50 or 100...)

 

Anyway... my host is moving to PHP 5.5 at the end of the month, and when I tested it, it was all good, except for the ability to sort.  I think it's this that is the problem:


 function pparams($sort) {global $sponsor, $school, $student, $instrument, $room, $time;}

                     if (!$sort)
                     $sort = "time";

This is because "register globals" is not supported with 5.5. 

 

Any suggestions on how to make it work?

 

Thanks.

Edited by wkilc
Link to comment
Share on other sites

The code you've posted doesn't make sense in any PHP version, because you're defining a function with no effect whatsoever:

function pparams($sort) {global $sponsor, $school, $student, $instrument, $room, $time;}

And then you try to access the $sort parameter from outside of the function:

if (!$sort)
    $sort = "time";

Obviously the closing brace of the function definition is misplaced. Whether that's a copy-and-paste error or your real code, I don't know.

 

In any case: If you want us to help you, we need the concrete error symptoms, all PHP error messages and all relevant code. It's not enough to tell us what you think is wrong.

Link to comment
Share on other sites

global variables as in the type illustrated in your snippet have not been changed at all.  I find the name somewhat misleading for many people, because any variable in PHP declared in the "script" scope, is global.

 

However, unlike many other static languages, global variables are not visible inside of functions.  

Thus the global keyword simply makes an existing global/script variable available inside the function, as in your example.

 

Register globals is a long deprecated and highly insecure feature that when turned on, will automatically make all user and server supplied variables into individually named global variables.  This would allow an attacker to attempt to manipulate your apps by calling scripts using lists of get or post, or cookie variables they supply.  It has been turned off by default literally for years, and you should not have been using it.

 

If in fact your app is broken for this reason, you should fix it.

 

The superglobals like $_SERVER, $_GET, $_POST etc. exist to provide you user input and url parameters.

 

In general, you can pass variables into your functions, rather than having long lists of globals, but even if you don't fix that, at least make sure you fix the register_globals related code, by finding those places where your code was relying on that, and getting the values from $_GET or $_POST.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.