Jump to content

Redirecting a user to another page?


Solarpitch

Recommended Posts

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

[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]
<?php
session_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

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.