Coding redirect in an else statement after the header

This is a discussion on "Coding redirect in an else statement after the header" within the PHP Forum section. This forum, and the thread "Coding redirect in an else statement after the header are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Apr 19th, 2007, 03:21
Junior Member
Join Date: Apr 2007
Location: Kansas
Age: 18
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to BRONIC
Unhappy Coding redirect in an else statement after the header

I am trying to get my page to redirect to a members only page if login is true. The page that I need it to go to is Downloads.php.

Could someone please help with my code?


This is the page code:

<?php
session_start();
header("Cache-control: private");
?>
<html>
<head>
<title>Check Log</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" TYPE="text/css">
<style type="text/css">
<!--
body,td,th {
font-family: Cooper Black;
font-size: 18px;
color: #CC0000;
}
body {
background-color: #000000;
}
a {
font-size: 24px;
color: #FFFFFF;
}
a:visited {
color: #CC0000;
}
a:hover {
color: #00FF00;
}
a:active {
color: #999999;
}
-->
</style>
</head>
<?php
if(!$_SESSION['name']){
echo "you are not logged in";
} else {
This is where i need it to redirect from (if login is true)
}
?>
Reply With Quote

  #2 (permalink)  
Old Apr 19th, 2007, 03:31
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Coding redirect in an else statement after the header

You need to mover the test into the first block of PHP - there's nothing in the logic to stop you doing so - and the add a call to header and an exit if the user is logged in - something like:

if (! $_SESSION['name']) {
header("Location: http://www.sheepbingo.co.uk/");
exit();
}
Reply With Quote
  #3 (permalink)  
Old Apr 19th, 2007, 03:46
Junior Member
Join Date: Apr 2007
Location: Kansas
Age: 18
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to BRONIC
Re: Coding redirect in an else statement after the header

Thank you so much, Im new to php so i don't know a whole lot and now my users can access the member only pages.

Thanks,

BRONIC
Reply With Quote
Reply

Tags
redirect

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding help: Combine Insert into and If/else statement! skuliaxe PHP Forum 6 Jan 23rd, 2008 17:50
PHP If Statement... mcdanielnc89 PHP Forum 16 Dec 9th, 2007 17:44
If..Else statement help IanW PHP Forum 3 Oct 6th, 2006 13:40
Help with If Statement. JohnMitch Classic ASP 2 Jan 5th, 2005 01:05
With Statement Trebz Classic ASP 2 Feb 2nd, 2004 14:56


All times are GMT. The time now is 21:49.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43