Jump to content

Creating a session and sending it thru


jw18

Recommended Posts

Hi there,

 

First I will say my experience in PHP is rather limited. Before posting on here I have searched a lot on Google to try and find the code. Nothing I have used seems to work... but I know what I want to do is simple.

 

Basically I have two pages on my website: Page1.php and Page 2.php

 

I do not want someone to be able to view Page2.php until they have viewed Page1.php. So I think I need to start a session on Page 1 which is checked on Page 2. This is the code I'm looking to find. If someone could help out or point me to something that would assist me, I'd greatly appreciate.

 

This is what I was working with:

 

Page 1:

<?php
session_start();
$_SESSION['name']="test";
?>

<a href="page2.php"> click here </a>

 

Page 2:

<?php
if ( !isset( $_SESSION['test'])) {
Header("Location: page1.php");
}
?>

Test Content 

 

Thank so much for any help at all!

 

Link to comment
https://forums.phpfreaks.com/topic/249026-creating-a-session-and-sending-it-thru/
Share on other sites

Ok. I tried adding that to page2 (page 1 already had it)

 

So now it's:

 

"<?php

session_start()

if ( !isset( $_SESSION['test'])) {

Header("Location: page1.php");

}

?>"

 

But it still just sends it back to page1.php when I start from that page. So it's like on page1 it's not creating a session or it's not passing it thru.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.