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.
|
|
|
|
|
![]() |
||
Coding redirect in an else statement after the header
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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) } ?> |
|
|
|
#2
|
|||
|
|||
|
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(); } |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Tags |
| redirect |
| Thread Tools | |
|
|
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 |