Zurechtweiser
Zurechtweiser

Reputation: 1216

Using sessions to transport a variable over multiple pages

I want to make a transition page, to forward "URL" to. I have this code. Self explanatory. !var means that some var is not given. URL is some url like http://domain.com

session_start();
if (!$some_variable) {
  $data = "http://localhost/";
  $_SESSION['keks'] = $data;
  require("transition.php");
  exit();
}

transition.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Frameset</title>
</head>
<frameset rows="50%,50%">
  <frame src="above.php" name="Navigation">
  <frame src="http://www.domain.com" name="Daten">
  <noframes>
    <body>
      <p>Something</p>
    </body>
  </noframes>
</frameset>
</html>

above.php:

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title>
    </title>
  </head>
  <body>
    <div style="text-align: right;"><a href="<?php echo $_SESSION['keks']; ?>">Continue</a> 
    </div>
  </body>
</html>

Which leads to

<a href="">

Why is that so?

Upvotes: 0

Views: 557

Answers (2)

MrJ
MrJ

Reputation: 1938

It's always best to give full code and not use !var - just put in the correct variable here as it is less confusing. Secondly you don't have any session in above.php

Unknown file:

<?php
session_start();
if (!isset($_SESSION['keks'])) {
    //header("Location: ".URL, true, 301);
    $_SESSION['keks'] = "http://localhost/";
    require("transition.php");
    exit();
}
?>

above.php

<?php
session_start();
?>
<html>
<head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title></title>
</head>
<body>
    <div style="text-align: right;">
        <a href="<?php echo $_SESSION['keks']; ?>">Continue</a> 
    </div>
</body>
</html>

Upvotes: 1

PiTheNumber
PiTheNumber

Reputation: 23563

This should work:

session_start();
if (!isset($_SESSION['keks'])) {
   $data = 'URL';
   $_SESSION['keks'] = $data;
   require("transition.php");
   exit();
}

Also in above.php you need

<?php session_start(); ?>

To get the variable.

Upvotes: 0

Related Questions