Does PHP support user assigned Superglobal variables?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
somekid
Forum Newbie
Posts: 3
Joined: Wed Oct 16, 2002 7:13 pm

Does PHP support user assigned Superglobal variables?

Post by somekid »

Let me explain what I'm trying to do...

This is for a call center, and, among other thing, the progam is to track technical support calls. Each tech has their own unique login, and, when logged in, a session object is created w/their info.

The call log has information it pulls out of the database that doesn't change very often, like the problem type (in a dropdown box) and the solutions according to the problem type (also a dropdown box). I was hoping that, instead of using a "SELECT * FROM problemCode" on each page display I could just create a global (or super global from what PHP calls them it seems) array for ALL scripts to see, so there is only one select statement. This way MySQL can use it's time searching through call logs, or things that are actually changing. If the problemCode table is to be updated, then the array would be too.

Is this possible?

from "test1.php", the code
<?php
$GLOBALS['temp'] = "some text";
echo $GLOBALS['temp'];
?>

is fine, but after running that, then runing "test2.php"

<?php
echo $GLOBALS['temp'];
?>

is blank. Does PHP allow 'super global' variables assigned by the user?

Any suggestions, comments, tips, whatever would be greatly appreciated, thanks!
levi_501_dehaan
Forum Newbie
Posts: 10
Joined: Mon Oct 14, 2002 4:34 pm
Location: Glenwood Springs

Post by levi_501_dehaan »

what im getting here is you want to pass the same variables throught your scripts? if so then
I do believe that you can pass variables using session
ie
$someinfo = "someinformation you want everywhere";
session_register("someinfo");

then on any other page that has session_start(); at the top (probably all your pages if your already using sessions)

you can call your session variable using
$someinfo = $_SESSION["someinfo"];

you can assign stuff to session too without session register
$_SESSION["information"] = "data and stuff";
and call it with

$data = $_SESSION["information"];

try it out and let me know if it works.
-=Levi=-
somekid
Forum Newbie
Posts: 3
Joined: Wed Oct 16, 2002 7:13 pm

Post by somekid »

I want to pass the same variable througout my scripts for ALL users, where I am using $_SESSION['tech'] as an object w/variables and functions related to the individual tech. All the techs will share some information from the database, like the problem types, and I didn't want to put that in a session object so that there are 50 sessions, and all of them have the same information in them, if that makes sense.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

somekid
Forum Newbie
Posts: 3
Joined: Wed Oct 16, 2002 7:13 pm

Post by somekid »

volka, thanks for the links (and for not flaming me because I didn't search).

I hadn't thought of using serialize() and unserialize() to save an objects state, which would work perfectly to emulate a global object, and that is exactly what I was looking for.

Thanks again!
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i can't wait to be able to say/do all that and know what i'm talking about, all at the same time 8O

GIB ME TIME OBI-1, GIVE ME TIME!@#!@# :twisted:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Image
"I prefer tongue-tied knowledge to ignorant loquacity." - Cicero 55 B.C.
"Say not always what you know, but always know what you say." - Claudius 10 B.C. - 54 A.D.

and there are of course all those excellent tips from lord Polonius
http://the-tech.mit.edu/Shakespeare/hamlet/hamlet.1.3.html

;)
Post Reply