Solarpitch Posted January 7, 2007 Share Posted January 7, 2007 Hey guys,Ok first off . . I am using session variables. When a user goes to a page that they can only view when their logged in, I want the page to display "you must be logged in to view this section". Could I just redirect them to a login page? and if so . . . what code could I use to automatically redirect them?Thanks, Ger Link to comment https://forums.phpfreaks.com/topic/33260-redirecting-a-user-to-another-page/ Share on other sites More sharing options...
HoTDaWg Posted January 7, 2007 Share Posted January 7, 2007 [quote author=Solarpitch link=topic=121426.msg499277#msg499277 date=1168211762]Hey guys,Ok first off . . I am using session variables. When a user goes to a page that they can only view when their logged in, I want the page to display "you must be logged in to view this section". Could I just redirect them to a login page? and if so . . . what code could I use to automatically redirect them?Thanks, Ger[/quote]well, here it is.[code]<?phpsession_start();header("Cache-control: private"); if(isset($_SESSION['sessionname'])){//you are logged in!echo $brilliantcontent;}else{//you are not logged in, punk.//redirect to login page!header("Location:http://www.phpfreaks.com/");}?>[/code]hope this helps.HoTDaWg Link to comment https://forums.phpfreaks.com/topic/33260-redirecting-a-user-to-another-page/#findComment-155326 Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 [code]<?php session_start(); if (!isset($_SESSION['logged'])) { header("Location: http://yourdomain/login.php"); }?>[/code] Link to comment https://forums.phpfreaks.com/topic/33260-redirecting-a-user-to-another-page/#findComment-155328 Share on other sites More sharing options...
Solarpitch Posted January 7, 2007 Author Share Posted January 7, 2007 Ah . . so thats the main piece of code that does the job, thats great . . . thanks guys![code] header("Location: http://yourdomain/login.php");[/code] Link to comment https://forums.phpfreaks.com/topic/33260-redirecting-a-user-to-another-page/#findComment-155330 Share on other sites More sharing options...
HoTDaWg Posted January 7, 2007 Share Posted January 7, 2007 same thing either way.Thorpe, you punk. ;D Link to comment https://forums.phpfreaks.com/topic/33260-redirecting-a-user-to-another-page/#findComment-155331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.