/    Sign up×
Community /Pin to ProfileBookmark

Session Problem

im just a novice in php and when i try to test whether my session is working using this code i know that there was a problem please help me.

this is page 1

<?php

session_start();

$_SESSION[‘foo’] = “bar”;
?>
<a href=”page2.php”>goto page 2</a>

and this is page 2

<?php

session_start();

echo $_SESSION[‘foo’];
?>

but when i run this its just showing a blank page.

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@cs3mwJul 29.2007 — try this it is untested though!

On your second page

<?php

session_start();

$val=$_SESSION["foo"];

echo"$val";

?>
Copy linkTweet thisAlerts:
@mckintosh18authorJul 29.2007 — i tried it and still the same result i got.
Copy linkTweet thisAlerts:
@ixxalnxxiJul 30.2007 — this is my page 1
&lt;?php
session_start();
$_SESSION['foo'] = "asd";
?&gt;
&lt;a href="page2.php"&gt;goto page 2&lt;/a&gt;


page2
&lt;?php
session_start();
echo $_SESSION['foo'];
?&gt;
&lt;a href="page1.php"&gt;goto page 1&lt;/a&gt;


and its working fine.. are you sure your page1 has a .php extension?
Copy linkTweet thisAlerts:
@mckintosh18authorJul 30.2007 — i know its weird because all sessions example available in the web i tried and it didnt work but i tried one script which echos session variable at only one page and it works so maybe its the passing of variable was the problem or maybe my configuration can you help me on what is the proper configuration. btw i use php 5 and apache server.
Copy linkTweet thisAlerts:
@NogDogJul 30.2007 — To make sure you're seeing any run-time error messages, start each script with:
[code=php]
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
[/code]

(I'm putting my money one one or both pages having a "headers already sent" error. ? )
Copy linkTweet thisAlerts:
@mckintosh18authorJul 30.2007 — i am using zend text editor and what i found was a notice on page2.php says undefine variable. which is $_Session['foo'] and didnt find any notice and errors on page1.php
Copy linkTweet thisAlerts:
@NogDogJul 30.2007 — i am using zend text editor and what i found was a notice on page2.php says undefine variable. which is [color=red]$_Session['foo'][/color] and didnt find any notice and errors on page1.php[/QUOTE]

If the red-highlighted text is an exact copy of the error, make sure that you use all capital letters for [b]$_
SESSION[/b].
Copy linkTweet thisAlerts:
@mckintosh18authorJul 30.2007 — no its was all capital sorry if i typed it that way.
×

Success!

Help @mckintosh18 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...