Title: Redirect Error
Last modified: August 19, 2016

---

# Redirect Error

 *  Resolved [dzirkelb](https://wordpress.org/support/users/dzirkelb/)
 * (@dzirkelb)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/)
 * I am trying to add a redirect on one of my pages and am receiving this error:
 * Warning: Cannot modify header information – headers already sent by (output started
   at D:Dee-incwp-includespost-template.php:797) in D:Dee-incwp-contentpluginsexec-
   phpincludesruntime.php(41) : eval()’d code on line 2
 * Here is the code I am adding directly into the html editor of wordpress:
 *     ```
       <?php
       header("Location: http://www.google.com");
       ?>
       ```
   
 * Here is the rest of the code for the html editor of the page:
 *     ```
       <link href="/wp-content/themes/destination/commerce/Commerce.css" rel="stylesheet" type="text/css" />
       <script src="/wp-content/themes/destination/commerce/TrackingSearch.asp?txtSearch=<?php echo $_GET["txtSearch"]; ?>&RadioSearch=<?php echo $_GET["RadioSearch"]; ?>" type="text/javascript"></script>
       ```
   
 * Any ideas on how to get past this error? I will change the criteria to redirect
   once I get this fixed.

Viewing 12 replies - 1 through 12 (of 12 total)

 *  [mydanblog](https://wordpress.org/support/users/mydanblog/)
 * (@mydanblog)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836721)
 * Yeah, if you are telling it to call the header function within the editor, then
   it will add that code at a point when the header’s already been called.
 * Besides that, I am not sure that what you are trying to do is good practice. 
   Are you trying to permanently redirect one page?
 * I would check out a plugin called Quick Page/Post Redirect – it may do what you
   are looking for, and do it in a way that won’t kill your google rankings.
 *  Thread Starter [dzirkelb](https://wordpress.org/support/users/dzirkelb/)
 * (@dzirkelb)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836762)
 * The redirect will be an if then statement. It looks to see if the user is logged
   in, if not, then it redirects them to the login page. The page is burried in 
   the site also, and will have no need to be ranked on google.
 * Currently, I have the page redirecting using a javascript code, but that code
   is ran after the page is rendered. Which, in turn, causes the page to load, then
   redirect, opposed to redirect before loading.
 *  [mydanblog](https://wordpress.org/support/users/mydanblog/)
 * (@mydanblog)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836829)
 * Oh, wow. You are doing a true dynamic redirect. Ok, then.
 * I think the code you want to place will look like this:
 *     ```
       if ( is_page('51') && !is_user_logged_in() ) {
              header("Location: http://www.google.com");
          }
       ```
   
 * The trick is going to be getting before the header call.
 * You could add this just above get_header() of your page.php file, then it will
   run this check before a page loads. Change 51 to whatever your page id is that
   you want to check.
 *  Thread Starter [dzirkelb](https://wordpress.org/support/users/dzirkelb/)
 * (@dzirkelb)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836843)
 * A problem I run into, is since this is wordpress, there isn’t actually a page.
   php file created. Maybe it’ll be easier for you to look at what I am talking 
   about:
 * [http://www.dee-inc.com/index.php/dee-e-commerce-center/](http://www.dee-inc.com/index.php/dee-e-commerce-center/)
 * Browse to that link, and then click the link “Live, Real-Time Order Tracking”.
 * You will notice it takes you to the page where you would abe able to do searches;
   however, since you are not logged in, it will redirect you. I am in search to
   get rid of loading the page, then redirecting.
 * And, since this is wordpress, there isn’t an actual page created that I can go
   to and edit the code. I am having to add the code directly into the html of the
   page, which is why I am struggling so much.
 * This seems to be a common problem, with a lot of it being caused by empty lines
   in the .php page, but I don’t have a .php page to look at, or at least I do not
   know what one to look at.
 * And, I only want to check to see if they are logged in for about 5 pages, not
   the other 100 on the site.
 *  [mydanblog](https://wordpress.org/support/users/mydanblog/)
 * (@mydanblog)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836847)
 * Hmm… Let me ask you a couple of questions that might get me thinking in the right
   direction:
 * 1. How did you create the page for commerce-tracking-search? Did you create it
   as a wordpress page?
 * 2. If you go into WordPress Dashboard=>appearance=>editor, do you see Page Template
   listed on the right hand side? If not, list the first ten things you see in that
   right hand column.
 *  Thread Starter [dzirkelb](https://wordpress.org/support/users/dzirkelb/)
 * (@dzirkelb)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836851)
 * For 1, it is a bit tricky.
 * The commerce-tracking-seach page has the following code which I added in the 
   html editor on the page itself:
 *     ```
       <link href="/wp-content/themes/destination/commerce/Commerce.css" rel="stylesheet" type="text/css" />
       <script src="/wp-content/themes/destination/commerce/TrackingSearch.asp?txtSearch=<?php echo $_GET["txtSearch"]; ?>&RadioSearch=<?php echo $_GET["RadioSearch"]; ?>" type="text/javascript"></script>
       ```
   
 * So, it basically does nothing but calls my previously coded .asp page, which 
   is this:
 *     ```
       <!-- #include file="dbQS.asp" -->
       <%
       strSearch = request.querystring("txtSearch")
       strRadioSearch = request.querystring("RadioSearch")
       strCustID = request.cookies("CustID")
       strPWD = request.cookies("PWD")
       strEmail = request.cookies("Email")
       strDisplay = ""
   
       if len(Request.QueryString("FP")) > 0 then
       	strFP = Request.QueryString("FP")
       else
       	strFP = "/index.php/dee-e-commerce-center/commerce-tracking-search/"
       end if
   
       strDisplay = strDisplay & "<html>"
   
       if strCustID = "" then
       	strDisplay = strDisplay & "<body onload=Redirect()>"
       else
       	strDisplay = strDisplay & "<body>"
       end if
   
       strDisplay = strDisplay & "<br>"
       strDisplay = strDisplay & "<br>"
       strDisplay = strDisplay & "Search By:"
       strDisplay = strDisplay & "<form action='' method=get id=frmGeneral name=frmGeneral>"
       strDisplay = strDisplay & "	<input type=hidden id=hidFP name=hidFP value="&strFP&">"
       strDisplay = strDisplay & "	<p>"
       strDisplay = strDisplay & "		<input type=radio id=RadioSearch name=RadioSearch value=CustPO checked>PO # |"
       strDisplay = strDisplay & "		<input type=radio id=RadioSearch name=RadioSearch value=DeeOrder"
       									if strRadioSearch = "DeeOrder" then
       										strDisplay = strDisplay & " checked"
       									end if
       								strDisplay = strDisplay & ">Dee Order # |"
       strDisplay = strDisplay & "		<input type=radio id=RadioSearch name=RadioSearch value=CustItem"
       									if strRadioSearch = "CustItem" then
       										strDisplay = strDisplay & " checked"
       									end if
       								strDisplay = strDisplay & ">Item # |"
       strDisplay = strDisplay & "		<input type=radio id=RadioSearch name=RadioSearch value=Part"
       									if strRadioSearch = "Part" then
       										strDisplay = strDisplay & " checked"
       									end if
       								strDisplay = strDisplay & ">Mfg Part # |"
       strDisplay = strDisplay & "	</p>"
       strDisplay = strDisplay & "	<input type=text id=txtSearch name=txtSearch value='"&strSearch&"' class=Notes>"
       strDisplay = strDisplay & "	<input type=submit value=Search id=SubmitSearch name=SubmitSearch>"
       strDisplay = strDisplay & "</form>"
   
       if len(strSearch) > 0 then
       	ssql = "SELECT [ORDER DETAILS].[ORDER #] as OrdNum, ORDERS.[CUST PO #] as CustPO, [ORDER DETAILS].[PART_#] as Part, [ORDER DETAILS].[CUST ITEM #] as CustItem, [ORDER DETAILS].[MFG_NAME] as MfgName, [ORDER DETAILS].[QTY] as Qty, [ORDER DETAILS].[REQ SHIP DATE] as RSD, [ORDER DETAILS].[LINE_SERIAL #] as LineSerial"
       	ssql = ssql & " FROM ORDERS INNER JOIN [ORDER DETAILS] ON ORDERS.[ORDER #] = [ORDER DETAILS].[ORDER #]"
   
       	select case strRadioSearch
       		case "CustPO"
       			ssql = ssql & " WHERE (ORDERS.[CUST PO #] = '"&strSearch&"') AND (ORDERS.[CUSTOMER #] = '"&strCustID&"') AND (ORDERS.[BuyerEmail] = '"&strEmail&"')"
       		case "DeeOrder"
       			ssql = ssql & " WHERE ([ORDER DETAILS].[ORDER #] = '"&strSearch&"') AND (ORDERS.[CUSTOMER #] = '"&strCustID&"') AND (ORDERS.[BuyerEmail] = '"&strEmail&"')"
       		case "Part"
       			ssql = ssql & " WHERE ([ORDER DETAILS].[PART_#] like '%"&strSearch&"%') AND (ORDERS.[CUSTOMER #] = '"&strCustID&"') AND (ORDERS.[BuyerEmail] = '"&strEmail&"')"
       		case "CustItem"
       			ssql = ssql & " WHERE ([ORDER DETAILS].[CUST ITEM #] like '%"&strSearch&"%') AND (ORDERS.[CUSTOMER #] = '"&strCustID&"') AND (ORDERS.[BuyerEmail] = '"&strEmail&"')"
       	end select
   
       	set rs = Server.CreateObject ("adodb.Recordset")
       	rs.Open ssql, dbc, adOpenForwardOnly, adLockReadOnly
   
       	if rs.eof then
       		intNumRec = 0
       	else
       		intNumRec = 1
   
       		strDisplay = strDisplay & "<table>"
       		strDisplay = strDisplay & "	<tr>"
       		strDisplay = strDisplay & "		<th>Cust PO#</th>"
       		strDisplay = strDisplay & "		<th>Order#</th>"
       		strDisplay = strDisplay & "		<th>Cust Item#</th>"
       		strDisplay = strDisplay & "		<th>Part#</th>"
       		strDisplay = strDisplay & "		<th>Mfg Name</th>"
       		strDisplay = strDisplay & "		<th>Qty</th>"
       		strDisplay = strDisplay & "		<th>Req Ship Date</th>"
       		strDisplay = strDisplay & "		<th>Invoice Date</th>"
       		strDisplay = strDisplay & "		<th>Status</th>"
       		strDisplay = strDisplay & "	</tr>"
       			do while not rs.EOF
       		strDisplay = strDisplay & "		<tr>"
       		strDisplay = strDisplay & "			<td>"&rs("CustPO")&"</td>"
       		strDisplay = strDisplay & "			<td>"&rs("OrdNum")&"</td>"
       		strDisplay = strDisplay & "			<td>"&rs("CustItem")&"</td>"
       		strDisplay = strDisplay & "			<td>"&rs("Part")&"</td>"
       		strDisplay = strDisplay & "			<td>"&rs("MfgName")&"</td>"
       		strDisplay = strDisplay & "			<td>"&rs("Qty")&"</td>"
       		strDisplay = strDisplay & "			<td>"&rs("RSD")&"</td>"
       		strDisplay = strDisplay & "			<td></td>"
       		strDisplay = strDisplay & "			<td>Open</td>"
       		strDisplay = strDisplay & "			<td><a href=# onclick=Tracking("&rs("LineSerial")&")>Track</a></td>"
       		'strDisplay = strDisplay & "			<td><a href=custorderedit1.asp?PONum="&rs("CustPO")&"&OrdNum="&rs("OrdNum")&"&LS="&rs("LineSerial")&" Title='Click To Edit This Line Item'>Edit</td>"
       		strDisplay = strDisplay & "		</tr>"
       			rs.movenext
       			loop
   
       		strDisplay = strDisplay & "</table>"
   
       	end if
   
       	rs.Close
       	set rs = nothing
   
       	ssql = "SELECT [ORDER #] as OrdNum, [CUST PO #] as CustPO, [PART_#] as Part, [CUST ITEM #] as CustItem, [MFG_NAME] as MfgName, [QTY] as InvQty , [INVOICE DATE] as InvDate, [LINESERIAL#] as LineSerial"
       	ssql = ssql & " FROM [INVOICE DETAILS]"
   
       	select case strRadioSearch
       		case "CustPO"
       			ssql = ssql & "WHERE ([CUST PO #] = '"&strSearch&"') AND ([CUSTOMER #] = '"&strCustID&"') AND ([BuyerEmail] = '"&strEmail&"')"
       		case "DeeOrder"
       			ssql = ssql & "WHERE ([ORDER #] = '"&strSearch&"') AND ([CUSTOMER #] = '"&strCustID&"') AND ([BuyerEmail] = '"&strEmail&"')"
       		case "Part"
       			ssql = ssql & "WHERE ([PART_#] like '%"&strSearch&"%') AND ([CUSTOMER #] = '"&strCustID&"') AND ([BuyerEmail] = '"&strEmail&"')"
       		case "CustItem"
       			ssql = ssql & "WHERE ([CUST ITEM #] like '%"&strSearch&"%') AND ([CUSTOMER #] = '"&strCustID&"') AND ([BuyerEmail] = '"&strEmail&"')"
       	end select	
   
       	set rs = Server.CreateObject ("adodb.Recordset")
       	rs.Open ssql, dbc, adOpenForwardOnly, adLockReadOnly
   
       	if rs.EOF then
       		if intNumRec = 0 then
       			strDisplay = strDisplay & "<br>"
       			strDisplay = strDisplay & "Dee Does Not Show Any Open Orders For "&strSearch&" Customer# "&strCustID&" With Buyer Email Address "&strEmail&""
       			strDisplay = strDisplay & "<br>"
       			strDisplay = strDisplay & "<br>"
       			strDisplay = strDisplay & "<a href=/index.php/dee-e-commerce-center/login/>Click Here To Change Logon</a>"
       		end if
       	else
       		if intNumRec = 0 then
       			strDisplay = strDisplay & "<table>"
       			strDisplay = strDisplay & "	<tr>"
       			strDisplay = strDisplay & "		<th>Cust PO#</th>"
       			strDisplay = strDisplay & "		<th>Order#</th>"
       			strDisplay = strDisplay & "		<th>Cust Item#</th>"
       			strDisplay = strDisplay & "		<th>Part#</th>"
       			strDisplay = strDisplay & "		<th>Mfg Name</th>"
       			strDisplay = strDisplay & "		<th>Qty</th>"
       			strDisplay = strDisplay & "		<th>Req Ship Date</th>"
       			strDisplay = strDisplay & "		<th>Invoice Date</th>"
       			strDisplay = strDisplay & "		<th>Status</th>"
       			strDisplay = strDisplay & "	</tr>"
       				do while not rs.EOF
       				strDisplay = strDisplay & "<tr>"
       				strDisplay = strDisplay & "	<td>"&rs("CustPO")&"</td>"
       				strDisplay = strDisplay & "	<td>"&rs("OrdNum")&"</td>"
       				strDisplay = strDisplay & "	<td>"&rs("CustItem")&"</td>"
       				strDisplay = strDisplay & "	<td>"&rs("Part")&"</td>"
       				strDisplay = strDisplay & "	<td>"&rs("MfgName")&"</td>"
       				strDisplay = strDisplay & "	<td>"&rs("InvQty")&"</td>"
       				strDisplay = strDisplay & "	<td></td>"
       				strDisplay = strDisplay & "	<td>"&rs("InvDate")&"</td>"
       				strDisplay = strDisplay & "	<td>Invoiced</td>"
       				strDisplay = strDisplay & "	<td><a href=# onclick=Tracking("&rs("LineSerial")&")>Track</a></td>"
       				strDisplay = strDisplay & "</tr>"
   
       				rs.movenext
       				loop
       		end if
       	end if
   
       	rs.close
       	set rs=nothing
   
       	strDisplay = strDisplay & "</table>	"
       end if
   
       strDisplay = strDisplay & "</body>"
       strDisplay = strDisplay & "</html>"
   
       %>
       function Redirect()
       {
       	FP = document.frmGeneral.hidFP.value;
       	window.location = "/index.php/dee-e-commerce-center/login/?FP="+FP;
       }
   
       function Tracking(LS)
       {
       	window.open ("/wp-content/themes/Destination/commerce/Tracking.asp?LS="+LS+"", "", "track, width=800,height=300,scrollbars=yes,resizable=no,status=yes");
       }
   
       document.write("<%=strDisplay%>")
       ```
   
 * A little history as why it is done that way is we had this site previously coded
   in html and .asp, back in, oh, 1998 or so, and finally upgraded the site. In 
   the upgrade, we went to wordpress so certain people at our company can update
   the pages and add new content and what not. Everything our company does is coded
   using .asp and .net, so we have 0 experience using .php.
 * I learned some quick snippets to make our existing pages work with the .php site,
   but it is definately a workaround.
 * On top of that, we are hosting the site ourselves on an IIS 6.0 server (windows
   2003).
 * For question number 2, page template is listed on the right hand side. That page
   did have a blank line at the end of the code, so I removed that, but still the
   same problem.
 *  [mydanblog](https://wordpress.org/support/users/mydanblog/)
 * (@mydanblog)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836853)
 * Ok. I’ve got something to try.
 * For giggles and grins, bear with me and try this:
 * In the wordpress dashboard, goto appearance=>editor
 * On the right hand side, click on page template.
 * In the editor screen, look for get_header();
 * copy this ABOVE get_header();
 *     ```
       if ( is_page('commerce-tracking-search') && !is_user_logged_in() ) {
              header("Location: http://www.dee-inc.com/index.php/dee-e-commerce-center/login/?FP=/index.php/dee-e-commerce-center/commerce-tracking-search/");
          }
       ```
   
 * This should work if you created the commerce-tracking-search as a page within
   wordpress, using the default page template, and the page slug is commerce-tracking-
   search.
 *  Thread Starter [dzirkelb](https://wordpress.org/support/users/dzirkelb/)
 * (@dzirkelb)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836857)
 * I’m assuming I need to change the code of !is_user_logged_in() to my custom code
   to check if they are logged in, correct? I store it in a cookie, so I’d check
   that.
 *  [mydanblog](https://wordpress.org/support/users/mydanblog/)
 * (@mydanblog)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836859)
 * One more tweak… it’s a good idea to add an exit statement. Here is a revised 
   code snippet:
 *     ```
       if ( is_page('commerce-tracking-search') && !is_user_logged_in() ) {
              header("Location: http://www.dee-inc.com/index.php/dee-e-commerce-center/login/?FP=/index.php/dee-e-commerce-center/commerce-tracking-search/");
              exit;
          }
       ```
   
 *  [mydanblog](https://wordpress.org/support/users/mydanblog/)
 * (@mydanblog)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836860)
 * > I’m assuming I need to change the code of !is_user_logged_in() to my custom
   > code to check if they are logged in, correct? I store it in a cookie, so I’d
   > check that.
 * You are correct. feel free to use your custom code there.
 *  Thread Starter [dzirkelb](https://wordpress.org/support/users/dzirkelb/)
 * (@dzirkelb)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836867)
 * That did the trick like a charm, thanks a TON!!
 *  [mydanblog](https://wordpress.org/support/users/mydanblog/)
 * (@mydanblog)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836873)
 * You are quite welcome glad I could help!

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Redirect Error’ is closed to new replies.

## Tags

 * [Redirct](https://wordpress.org/support/topic-tag/redirct/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 12 replies
 * 2 participants
 * Last reply from: [mydanblog](https://wordpress.org/support/users/mydanblog/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/redirect-error-2/#post-1836873)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
