dotJoon
1
<?php session_start();?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>session_variable2</title>
</head>
<body>
<?php $myString =1 ; ?>
<a href="session_variable2-1.php">session_variable2-1.php</a><br>
<a href="session_variable2-1.php">session_variable2-2.php</a>
<?php $_SESSION['myString']=2; ?>
</body>
</html>
There are 2 links in http://dot.kr/x-test/session_variable2.php .
The code below is in the 1st link.
<?php session_start();?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>session_variable2-2</title>
</head>
<body>
<?php echo $_SESSION['myString'];?>
</body>
</html>
The code in the 2nd link is added to the code “<?php $myString =1 ; ?>”
to the 1st link like the following.
<?php session_start();?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>session_variable2-2</title>
</head>
<body>
[COLOR="Red"]<?php $myString =1 ; ?>[/COLOR]
<?php echo $_SESSION['myString'];?>
</body>
</html>
The output of the 2nd link produces $myString “1” instead of $_SESSION[‘myString’] “2”.
Although each name which is “mySring” is same, I think, $myString and $_SESSION[‘myString’] should be discriminated.
Can I make them discriminated with same name by your help?
system
2
they are 2 different variables stored in 2 separate memory locations.
this demo stores 2 different values for the same variable name and array key
<?php
$myStr = '$myStr as plain variable';
$_SESSION['$myStr'] = '$myStr as session variable';
echo $myStr.'<br />'.$_SESSION['$myStr'];
?>
felgall
3
Do you have register_globals turned off?
dotJoon
4
I don’t know how and where I can it turn off.
Where can I check whether I did it or not.
system
5
I’m not sure register_globals is the issue in this case :scratch:
normally it is turned off.
if I turn it on in my php.ini file and restart xampp, I still see 2 different values in the demo I posted.
dotJoon
6
I found there is a big difference between my code above and Kalon’s code below.
system
7
it makes no difference. as I said, the plain variable and session variable are stored in separate memory locations and so this demo code
<?php
$myStr = '$myStr as plain variable';
$_SESSION['myStr'] = 'myStr as session variable';
echo $myStr.'<br />'.$_SESSION['myStr'];
?>
also displays the 2 different values for each variable when I run it on my server.
dotJoon
8
Yes, as you said it displays the 2 different values for each variable when I run it on my server ( http://dot.kr/x-test/session_variable5.php ) like it on your server.
But it is 1 page.
Session has the meaning when it crosses the river between 2 pages.
[b]session_variable6.php [/b]
<html>
<head>
<meta charset="UTF-8">
<title>session_variable6</title>
</head>
<body>
<?php
$myString = "plain";
?>
<br>
<a href="session_variable6-1.php">session_variable6-1</a>
<?php $_SESSION['[SIZE="5"][COLOR="Red"]$[/COLOR][/SIZE]myStr'] = "session"; ?>
</body>
</html>
[b]session_variable6-1.php[/b]
<?php session_start();?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>session_variable6-1</title>
</head>
<body>
<?php
$myStr = "plain";
echo $_SESSION['[COLOR="Red"][SIZE="5"]$[/SIZE][/COLOR]myStr'];
?>
</body>
</html>
[b]output of session_variable6-1.php[/b]
session
You can test it in http://dot.kr/x-test/session_variable6.php.
[b]session_variable7.php[/b]
<?php session_start();?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>session_variable7</title>
</head>
<body>
<?php
$myString = "plain";
?>
<br>
<a href="session_variable7-1.php">session_variable7-1</a><br>
<?php $_SESSION['myStr'] = "session"; ?>
</body>
</html>
[b]session_variable7-1.php[/b]
<?php session_start();?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>session_variable6-1</title>
</head>
<body>
<?php
$myStr = "plain";
echo $_SESSION['myStr'];
?>
</body>
</html>
[b]output of session_variable7-1.php[/b]
plain
You can test it in http://dot.kr/x-test/session_variable7.php.
system
9
where is session_start() in session_variable6.php
dotJoon
10
I omitted it during posting.
Actual code in session_variable6.php is the code below.
[COLOR="Red"]<?php session_start();?>[/COLOR]
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>session_variable6</title>
</head>
<body>
<?php
$myString = "plain";
?>
<br>
<a href="session_variable6-1.php">session_variable6-1</a>
<?php $_SESSION['[SIZE="5"][COLOR="red"]$[/COLOR][/SIZE]myStr'] = "session"; ?>
</body>
</html>