473,857 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about using "global" on one page then using the variable on another page

I am taking over an exisitng app. I have the following function on one
page:

function check($v) {
global $user;
return $user->validate($v[1], $v[0]);
}

And it reference $user on the next page. Register_global s are set on the
existing server but I am moving to a new server where it is not. The code
of the next page is lilke:

session_registe r('user');
$user=$_SESSION['user'];

I also want to turn it around so it's:
$_SESSION['user'] = $user;

But that fails - $user is empty. By the way, $user is an object.

Any ideas to how to make sure:
$_SESSION['user'] = $user;

works on the second page?
Apr 5 '07 #1
2 1559
Paul wrote:
I am taking over an exisitng app. I have the following function on one
page:

function check($v) {
global $user;
return $user->validate($v[1], $v[0]);
}

And it reference $user on the next page. Register_global s are set on the
existing server but I am moving to a new server where it is not. The code
of the next page is lilke:

session_registe r('user');
$user=$_SESSION['user'];

I also want to turn it around so it's:
$_SESSION['user'] = $user;

But that fails - $user is empty. By the way, $user is an object.

Any ideas to how to make sure:
$_SESSION['user'] = $user;

works on the second page?

First of all, you don't need to call session_registe r(). Just set the
value in $_SESSION.

And ensure you are calling session_start() before *any* output (even
white space) on both pages.

If it still fails, enable all errors and display them. See if you're
getting any (errors, that is :-) ). If not, echo $user just before you
put in $_SESSION and see what's there. Also, in the second page, try

echo "<pre>\n";
print_r($_SESSI ON);
echo "</pre>\n";

to see what's actually in your $_SESSION superglobal.

It does work just fine.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 5 '07 #2
On 5 apr, 19:28, "Paul" <l...@invalid.c omwrote:
And it reference $user on the next page. Register_global s are set on the
existing server but I am moving to a new server where it is not. The code
of the next page is lilke:

session_registe r('user');
$user=$_SESSION['user'];

I also want to turn it around so it's:
$_SESSION['user'] = $user;

But that fails - $user is empty. By the way, $user is an object.

Any ideas to how to make sure:
$_SESSION['user'] = $user;

works on the second page?
Like Jerry said, drop the session_registe r(). Also, on the original
page you'd have to put the object in the session, not in the second
page. So:

First page:
$_SESSION['user'] = $user;

And then you can use it on the next page (if the object hasn't got
recursive/self-referencing qualities).

--
Rik
"Why break one foot if you've got two of them?"

Apr 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2713
by: mrbog | last post by:
I have an array/hash that stores path information for my app. As in, what directory this is in, what directory that's in, what the name of the site is, what the products are called, etc. It's called $glb. So, every function so far looks like this: function something() { global $glb; }
7
2692
by: Lyn | last post by:
Hi and Season's Greetings to all. I have a question regarding the use of a qualifier word "Global". I cannot find any reference to this in Access help, nor in books or on the Internet. "Global" seems to be recognised by Access in at least three cases:- 1) "Global Const". Recently someone in this group helped me resolve a problem, and it involved the use of a Global Const. By Googling "Global Const", I got plenty of hits -- but they...
5
3500
by: j | last post by:
Anyone here feel that "global variables" is misleading for variables whose scope is file scope? "global" seems to imply global visibility, while this isn't true for variables whose scope is file scope. If you have a variable whose scope is file scope in another translation unit, you have to provide a local declaration to access that variable from the other translation unit. Also, I don't see "global variable" used once in the standard....
44
2060
by: Mohanasundaram | last post by:
int i = 10; int main() { int i = 20; return 0; } Hi All, I want to access the global variable i inside the main. Is there
4
3540
by: BB | last post by:
Hello all, I might be missing something here, but am trying to understand the difference between using application-level variables--i.e. Application("MyVar")--and global variables--i.e. public myVar as string, etc. It seems to me that the scope and duration are the same, as they both are there while the application is running, and both go away when it quits. I presume that one difference is that the application state can be "flushed," such...
53
26438
by: fdmfdmfdm | last post by:
This is an interview question and I gave out my answer here, could you please check for me? Q. What are the memory allocation for static variable in a function, an automatic variable and global variable? My answer: static variable in function and global variable are allocated in head, and automatic variable is allocated in stack. Right?
2
1316
by: Sir Psycho | last post by:
Is there a way to set a global variable without using the Session object? I basically want to be able to track if a visitor is logged in without starting a Session. Is there such a thing as a global variable that stays alive?
8
3455
by: yinglcs | last post by:
Hi, I read this article about global variable in c: http://www.phim.unibe.ch/comp_doc/c_manual/C/SYNTAX/glo_int_vars.html But I have a few questions 1. how can I declare the global variable so that it can be set/get by other files? 2. If I have multiple instance of the same program running in the same machine (linux), will each program instance has its own of global
112
5509
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions that may print some messages. foo(...) { if (!silent)
4
3418
ChrisWang
by: ChrisWang | last post by:
Hi, I am having trouble understanding the use of 'global' variables I want to use a global variable with the same name as a parameter of a function. But I don't know how to use them at the same time. Here is a snippet of example code: def foo (a): global p global a p = a + 3 #here "a" will be reference to the global one a = 1
0
9768
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10711
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7104
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5971
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.