jbingman Posted September 1, 2007 Share Posted September 1, 2007 I've been trying to use the header(); function to redirect to other pages such as... Login not successful *redirects to login page*. but whenever i try to use the header it says that its being used by another line already. and no where in my code is there another line like it. what does this error mean and how do i fix it? Quote Link to comment https://forums.phpfreaks.com/topic/67561-solved-header-function/ Share on other sites More sharing options...
pocobueno1388 Posted September 1, 2007 Share Posted September 1, 2007 It's probably giving you an error because the header function has to be used before any output to the browser. Post your code and we can help you figure out where to put it. Quote Link to comment https://forums.phpfreaks.com/topic/67561-solved-header-function/#findComment-339357 Share on other sites More sharing options...
jbingman Posted September 1, 2007 Author Share Posted September 1, 2007 <? session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Admin</title> <link href="/mainstyle.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" href="favicon.ico" /> </head> <body> <?php if (!$_SESSION["valid_user"]) { // User not logged in, redirect to login page header("location:login.php"); } ?> <center> <table width="895" height="134" style="background-image:url(/Untitled-3.gif)"> <tr> <th width="99"><a href="/index.shtml"><img src="/logotrans3.gif" alt="logoSAR" width="118" height="126" border="0" /></a></th> <th width="782" height="128" scope="col"><a href="/index.shtml"><img src="/SARtitle2.gif" alt="sartitle" width="656" height="82" border="0" /></a></th> </tr> </table> <table width="895" height="822"> <tr> <td width="140" height="806" valign="top"><table width="140" height="232" border="0"> <tr> <th width="134" height="22" scope="row"><div align="left"><a href="http://www.fresnosar.com/index.shtml">Home</a>-</div></th> </tr> <tr> <th height="22" scope="row"><div align="left"><a href="http://www.fresnosar.com/about.html">About</a>-</div></th> </tr> <tr> <th height="22" scope="row"><div align="left"><a href="http://www.fresnosar.com/update/news.html">Current News</a>-(<a href="admin/newsedit.php">edit</a>)</div></th> </tr> <tr> <th height="22" scope="row"><div align="left"><a href="http://www.fresnosar.com/cal/calendar.html">Calendar</a>-(<a href="admin/caledit.php">edit</a>)</div></th> </tr> <tr> <th height="22" scope="row"><div align="left"><a href="http://www.fresnosar.com/photo/albums.html">Photos In Action</a>-(<a href="admin/picedit.php">add/edit</a>)</div></th> </tr> <tr> <th height="22" scope="row"><div align="left"><a href="http://www.fresnosar.com/vid/videos.html">Videos</a>-(<a href="admin/videdit.php">add/edit</a>)</div></th> </tr> <tr> <th height="22" scope="row"><div align="left"><a href="http://www.fresnosar.com/links.html">SAR Links</a>-(<a href="admin/linksedit.php">edit</a>)</div></th> </tr> <tr> <th height="22" scope="row"><div align="left"><a href="http://www.fresnosar.com/app/apply.html">Apply</a>-</div></th> </tr> <tr> <th height="20" scope="row"><div align="left"><a href="http://www.fresnosar.com/contact.html">Contact</a>-</div></th> </tr> </table></td> <td width="642" align="center" valign="top"> <div class="img"> <p>Admin Page </p> </div> </td> <td width="97" align="left" valign="top"> <? // Display last login date // Display logout link echo "<p><a href=\"logout.php\">logout</a></p>"; ?> </td> </tr> </table> <table width="895" height="57"> <tr> <th height="51" style="border:none"><h6><a href="http://www.fresnosar.com/index.shtml">Home</a> | <a href="http://www.fresnosar.com/about.html">About</a> | <a href="http://www.fresnosar.com/update/news.html">News</a> | <a href="http://www.fresnosar.com/cal/calendar.html">Calendar</a> | <a href="http://www.fresnosar.com/photo/albums.html">Photos</a> | <a href="http://www.fresnosar.com/vid/videos.html">Videos</a> | <a href="http://www.fresnosar.com/links.html">Links</a> | <a href="http://www.fresnosar.com/app/apply.html">Apply</a> | <a href="http://www.fresnosar.com/contact.html">Contact</a></h6> <h6>Copyright 2007 FrameWorks Studios <a href="mailto:admin@fresnosar.com">admin@fresnosar.com</a>. All rights reserved.</h6></th> </tr> </table> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/67561-solved-header-function/#findComment-339358 Share on other sites More sharing options...
pocobueno1388 Posted September 1, 2007 Share Posted September 1, 2007 Try this: <?php session_start(); if (!$_SESSION["valid_user"]) { // User not logged in, redirect to login page header("location:login.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Admin</title> <link href="/mainstyle.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" href="favicon.ico" /> </head> <body> <center> <table width="895" height="134" style="background-image:url(/Untitled-3.gif)"> <tr> <th width="99"><a href="/index.shtml"><img src="/logotrans3.gif" alt="logoSAR" width="118" height="126" border="0" />[/url]</th> <th width="782" height="128" scope="col"><a href="/index.shtml"><img src="/SARtitle2.gif" alt="sartitle" width="656" height="82" border="0" />[/url]</th> </tr> </table> <table width="895" height="822"> <tr> <td width="140" height="806" valign="top"><table width="140" height="232" border="0"> <tr> <th width="134" height="22" scope="row"><div align="left">Home-</div></th> </tr> <tr> <th height="22" scope="row"><div align="left">About-</div></th> </tr> <tr> <th height="22" scope="row"><div align="left">Current News-(<a href="admin/newsedit.php">edit[/url])</div></th> </tr> <tr> <th height="22" scope="row"><div align="left">Calendar-(<a href="admin/caledit.php">edit[/url])</div></th> </tr> <tr> <th height="22" scope="row"><div align="left">Photos In Action-(<a href="admin/picedit.php">add/edit[/url])</div></th> </tr> <tr> <th height="22" scope="row"><div align="left">Videos-(<a href="admin/videdit.php">add/edit[/url])</div></th> </tr> <tr> <th height="22" scope="row"><div align="left">SAR Links-(<a href="admin/linksedit.php">edit[/url])</div></th> </tr> <tr> <th height="22" scope="row"><div align="left">Apply-</div></th> </tr> <tr> <th height="20" scope="row"><div align="left">Contact-</div></th> </tr> </table></td> <td width="642" align="center" valign="top"> <div class="img"> <p>Admin Page </p> </div> </td> <td width="97" align="left" valign="top"> <? // Display last login date // Display logout link echo "<p><a href=\"logout.php\">logout[/url]</p>"; ?> </td> </tr> </table> <table width="895" height="57"> <tr> <th height="51" style="border:none"><h6>Home | About | News | Calendar | Photos | Videos | Links | Apply | Contact</h6> <h6>Copyright 2007 FrameWorks Studios [email]admin@fresnosar.com[/email]. All rights reserved.</h6></th> </tr> </table> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/67561-solved-header-function/#findComment-339360 Share on other sites More sharing options...
jbingman Posted September 1, 2007 Author Share Posted September 1, 2007 YAY! thanks so much for you help. so all header();'s have to be before the doctype code? as well as the session_start(); right? Quote Link to comment https://forums.phpfreaks.com/topic/67561-solved-header-function/#findComment-339362 Share on other sites More sharing options...
pocobueno1388 Posted September 1, 2007 Share Posted September 1, 2007 Yes, those should both be before any output. All the "doctype" stuff is considered output to the browser Quote Link to comment https://forums.phpfreaks.com/topic/67561-solved-header-function/#findComment-339366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.