Author Topic: How to register a new global variable?  (Read 5770 times)

0 Members and 1 Guest are viewing this topic.

Offline dp

  • Newbie
  • *
  • Posts: 37
    • View Profile
How to register a new global variable?
« on: October 08, 2009, 03:28:05 PM »
Hi,
I'm working with Chris Mod for an alternative download directory xxx: xxx: 4homepages.   de/forum/index.   php?topic=7499.   msg33712#msg33712 and would like to use a new global variable to determine the name of the download folder, accessable from every part of the 4images script.   

So I tried just

global $dp_download_folder;

in includes/global.   php, index.   php and many others, but the variable was not accessible from any function or script in download.   php or functions.   php.   

As you see, I'm not very familiar to php and try my very best to learn.    For all you php-professionals arround here, this is a quiet simple question for sure.    So I hope you will have the answer.   

Many Thanks in advance!

Offline V@nо

  • Addicted member
  • ******
  • Posts: 1.223
    • View Profile
Re: How to register a new global variable?
« Reply #1 on: October 08, 2009, 04:25:39 PM »
You should ask this question under the topic it's related to, so people familiar with the mod could assist you (http://www.4homepages.de/forum/index.php?topic=3914.0#post_rule5)

P.S.
$dp_download_folder is not part of the mod, therefor you also should mention where it comes from...but that is under appropriate topic, please.
Your first three "must do" before you ask a question:
If I asked you to PM me, I meant PM to my primary account, this account doesn't accept PMs.

Offline dp

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: How to register a new global variable?
« Reply #2 on: October 08, 2009, 04:41:44 PM »
Thank you for your reply,

but my question is not related to the mod only, it's about the 4images script and php and the variable $dp_download_folder is just the new variable I want to declare as global and accessable for the whole script.

Many Greetings

Offline V@nо

  • Addicted member
  • ******
  • Posts: 1.223
    • View Profile
Re: How to register a new global variable?
« Reply #3 on: October 08, 2009, 04:47:11 PM »
Ok then.

The variable will be accessible anywhere in the script except for functions. in functions you'll need add
global $dp_download_folder;
Your first three "must do" before you ask a question:
If I asked you to PM me, I meant PM to my primary account, this account doesn't accept PMs.

Offline impss

  • Sr. Member
  • ****
  • Posts: 382
    • View Profile
    • Cusstom.net
Re: How to register a new global variable?
« Reply #4 on: October 08, 2009, 04:50:47 PM »
You can define the folder as a constant

In / includes / constants.php

above
?>

Add

define('DOWNLOAD_DIR''TheNameOfTheFolder');

Offline dp

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: How to register a new global variable?
« Reply #5 on: October 08, 2009, 09:21:47 PM »
Quote from: V@nо link=topic=26033. msg141896#msg141896 date=1255013231
Ok then.

The variable will be accessible anywhere in the script except for functions.  in functions you'll need add
global $dp_download_folder;

Ah, now I understand! It has to be declared INSIDE a function.
Well, this is quite different from other languages I'm working with like VB or Pascal (in very former days), where Variables should be declared in front of the Code.

Thank you very much for youre immediate assistance!

Offline V@nо

  • Addicted member
  • ******
  • Posts: 1.223
    • View Profile
Re: How to register a new global variable?
« Reply #6 on: October 08, 2009, 10:22:49 PM »
just to clearify, it does not have to be declared inside a function, but if it's declared inside a function, then if you need access that variable outside a function, you'll need use global BEFORE the variable declared. if no global or static used inside a function, then any variables used will be lost after exit the function.
Your first three "must do" before you ask a question:
If I asked you to PM me, I meant PM to my primary account, this account doesn't accept PMs.