jw18 Posted October 13, 2011 Share Posted October 13, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/249026-creating-a-session-and-sending-it-thru/ Share on other sites More sharing options...
trq Posted October 13, 2011 Share Posted October 13, 2011 You need a call to session_start() in all pages that use $_SESSION. Quote Link to comment https://forums.phpfreaks.com/topic/249026-creating-a-session-and-sending-it-thru/#findComment-1278944 Share on other sites More sharing options...
jw18 Posted October 13, 2011 Author Share Posted October 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/249026-creating-a-session-and-sending-it-thru/#findComment-1278948 Share on other sites More sharing options...
trq Posted October 13, 2011 Share Posted October 13, 2011 You haven't set $_SESSION['test'], you have set $_SESSION['name']. Quote Link to comment https://forums.phpfreaks.com/topic/249026-creating-a-session-and-sending-it-thru/#findComment-1278950 Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 13, 2011 Share Posted October 13, 2011 Page 1 <?php session_start(); $_SESSION['name']="test"; ?> <a href="page2.php"> click here </a> Page2 <?php session_start(); if (!isset($_SESSION['name'])) { Header("Location: page1.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249026-creating-a-session-and-sending-it-thru/#findComment-1278997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.