How do I set the session on a page, so that if I were to type the direct link for the page into the address bar, it doesn't display, instead the user would be redirected to the homepage or login page?
maydhyam 38 Posting Pro :)
Recommended Answers
Jump to PostI used the following code:
<?php session_start(); if (empty($_SESSION['username'])) { header("location:index.php"); exit; } ?>
Jump to PostHere is what I suggest:
Create a page called secure.php
add the following code as it is: ONLY change " your_login_page "<?php session_start(); if (empty($_SESSION['username'])) { header("location:your_login_page.php"); exit; } ?>
Then in your other pages that you want secure, add:
<?php require_once('secure.php'); …
All 8 Replies
rgviza 8 Light Poster
maydhyam 38 Posting Pro :)
Vai 2 Junior Poster in Training
maydhyam 38 Posting Pro :)
Vai 2 Junior Poster in Training
maydhyam commented: Good work, well done... :) +1
maydhyam 38 Posting Pro :)
maydhyam 38 Posting Pro :)
maydhyam 38 Posting Pro :)
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.