/    Sign up×
Community /Pin to ProfileBookmark

Sessions not working or remembering variables

I’m trying to make a login page, but i can’t get sessions to work. I’ve tried many different ways of doing it:

session_register
$_SESSION[‘variable’]
$HTTP_SESSION_VARS[‘variable’]

but it just don’t work. I created a miniture script just to test it and even that don’t work. Here it is:

PAGE 1

<? session_start ();
$_SESSION[‘variable’]=”hello”;
?>
<html>
<head>
<title>Test Page 1</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>
<body>
<a href =”page2.php”>page 2</a>
</body>
</html>


———-

page 2

<? session_start (); ?>
<html>
<head>
<title>Test Page 2</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>

<body>
<?
print $_SESSION[‘variable’];
?>
</body>
</html>


________________________________

Now is there something wrong with that or is there something else i need to do? Also is using Apache on my comp as a testing ground anything to do with it? I can’t see why but it did occur to me…

thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliFeb 16.2004 — Checks

  • 1. Make sure cookies are enabled in your browser.


  • 2. One other practice that I have used allways is once you are done setting up your session variables at a page close writing to session by using

    session_write_close();
  • Copy linkTweet thisAlerts:
    @olafFeb 16.2004 — Hallo,

    check your php.ini and make shure that the session.save_path is OK
    ×

    Success!

    Help @foxache 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 6.18,
    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: @nearjob,
    tipped: article
    amount: 1000 SATS,

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

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...