Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

page-1 variable TO page-any ! how 1

Status
Not open for further replies.

jonybd

Programmer
Joined
Nov 3, 2002
Messages
166
Location
BE
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
I have 2 page one.php , two.php, problem is i want to see or get variables, value from different pages. for example i want to store value in page-1 i want to see / get it from page-10 or page-20 .. i was trying the following but not working plz help.
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ One.php:
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
<?
session_start();
$_SESSION['test'] = 'Testing to see this variable in all page when ever i wanted';
echo $_SESSION['test']; //displaying here perfectly
?>

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ two.php: _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
<?
session_start();
echo $_SESSION['test'];
?>
 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
One.php
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
<?
session_start();
$HTTP_SESSION_VARS ['test'] = 'Testing it';
echo $_SESSION['test'];
?>
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Two.php
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
<?
session_start();
echo $HTTP_SESSION_VARS ['test'];
?>

See error::::::::::
Notice: Undefined variable: HTTP_SESSION_VARS in d:\inetpub\ on line 10
 
PHP Version 4.2.3

this is the see.php page where i want to see session 'test' value
<html>
<head>
<title>Logout</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

<?
session_start();
echo $HTTP_SESSION_VARS['test'];
?>
</body>
</html>

end this is the Php.php page where i will set session 'test' value
<html>
<head>
<title>Logout</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<BR>
<p align=&quot;center&quot;>
JonY Php Tutorial
<BR>
-----------------------------------------------------------------
</p>

<?
/*
**********************
* php Variable Declareing
**********************
*/
session_start();
$_SESSION ['test'] = 'Testing it';
echo $_SESSION['test'];
phpinfo();
?>
</body>
</html>
 
PHP Version 4.2.3

this is the see.php page where i want to see session 'test' value
<html>
<head>
<title>Logout</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

<?
session_start();
echo $_SESSION['test'];
?>
</body>
</html>

end this is the Php.php page where i will set session 'test' value
<html>
<head>
<title>Logout</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<?
/*
**********************
* php Variable Declareing
**********************
*/
session_start();
$_SESSION ['test'] = 'Testing it';
echo $_SESSION['test'];
phpinfo();
?>
</body>
</html>
 
There's the start of your troubles. Unless you are using output buffering, you cannot have HTML output happen before session_start() occurs.

You should have been given an warning about using session_start() after you've started output. What is the setting of error_reporing in php.ini?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
**Move session_start() to the start of your scripts.
what do you mean by that ? where to do that ?

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Well thank u so much
i edit the php.ini

703-line: session.auto_start = 0
to session.auto_start = 1

now its working

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
 
&quot;Move session_start() to the beginning of the script&quot; means take a script that looks like this:

<head>
<title>Logout</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<?
/*
**********************
* php Variable Declareing
**********************
*/
session_start();
$_SESSION ['test'] = 'Testing it';
echo $_SESSION['test'];
phpinfo();
?>
</body>
</html>

And make it look like:

<?php
session_start();
?>

<head>
<title>Logout</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<?
/*
**********************
* php Variable Declareing
**********************
*/
$_SESSION ['test'] = 'Testing it';
echo $_SESSION['test'];
phpinfo();
?>
</body>
</html>


I generally don't recommend setting session.auto_start to 1. Every one of your scripts ends up setting session variables even if you never use them.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
thanks its working now with your last post.
and mine -> 5 no. post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top