Jump to content

Recommended Posts

Hi!

I am new to PHP and I am still learning.

In PHP when I tried to create File Uploading Script, at first it was not working but when I enabled "register_globals = ON" It is now working but in php.ini it says

; You should do your best to write your scripts so that they do not require

; register_globals to be on;  Using form variables as globals can easily lead

; to possible security problems, if the code is not very well thought of.

; http://php.net/register-globals

So My question is How I can write my script with out using globals register

Link to comment
https://forums.phpfreaks.com/topic/195723-register-globals/
Share on other sites

Well it depends what you're trying to do. If you just need some variables accessible from all your scripts (for example, config settings), then it's common to place them all in one file (for example, config.php or config.inc) and use require to load them into the current script.

 

For example, if you have a config.php with the following contents:

 

<?php
$greeting = "Hello World!";
?>

 

and index.php with:

 

<?php
require('config.php');
echo "<h1>$greeting</h1>";
?>

 

Then $greeting would be displayed on the index page. Obviously not a particularly useful example but there are multitudes of variables that can be centralised with a config file (database connections, for example).

 

Not sure if that answers your question or not

Link to comment
https://forums.phpfreaks.com/topic/195723-register-globals/#findComment-1028240
Share on other sites

@DWilliams, register_globals has nothing at all to do with what you just posted.

 

It concerns 'magically' populating program variables from the same name $_GET, $_POST, $_COOKIE, $_FILES, $_SESSION, $_SERVER, and $_ENV variables, thereby allowing hackers to set any program variables and $_SESSION variables instead of just the intended variables.

Link to comment
https://forums.phpfreaks.com/topic/195723-register-globals/#findComment-1028243
Share on other sites

Mchl already addressed that. You write code that references the correct $_GET, $_POST, $_COOKIE, $_FILES, $_SESSION, $_SERVER, and $_ENV variables where the actual data is coming from.

 

If you are using session_register(), session_is_registered(), or session_unregister(), you will need to make additional changes in the code to use the $_SESSION array.

Link to comment
https://forums.phpfreaks.com/topic/195723-register-globals/#findComment-1028251
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.