what's wrong with this code. if( urldecode($cat) == 'crib / toddler sheets'){ header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.mysite.com/mypage.php?pcat=21"); echo "abc"; } PHP: I can see 'abc' printed on the page when I click this URL "mysite.com/product_listing.php?cat=crib+%2F+toddler+sheets". What should I do to redirect to mypage.php?pcat=21
Try this: if( urldecode($cat) == 'crib / toddler sheets'){ header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.mysite.com/mypage.php?pcat=21"); exit(); echo "abc"; } PHP:
I have tried this. There is no Warning or Notice on the page. It is very strange type of error. I don't know how to fix it.
Where are you getting the value of $cat from ? Can you post the code that is above the code that you have posted. Brew
Try this: if( urldecode($_GET['cat']) == 'crib / toddler sheets'){ header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.mysite.com/mypage.php?pcat=21"); echo "abc"; } PHP: Brew
That doesn't seem to be the problem, as he gets the output of "abc" in this example. http://forums.digitalpoint.com/showpost.php?p=3972422&postcount=1
Good point. How about echoing the result of urldecode($_GET['cat']) That may give a clue where to look next. Brew
This code is at top of the page. only database connection and session include file is above it. nico_swd is right $_GET is not a problem. Problem is in header function. It's not working.
Good Point. I am always getting 'Headers sent!' message. Now I put the following code on the top of the page above the connection include file. Now following lines are first 6 lines of page. <?php if (!headers_sent()){ if($pcat == 5){ header( "HTTP/1.1 301 Moved Permanently" ); header("Location: mypage.php?pcat=38"); echo "abc"; } } PHP: now i am not getting 'abc' printed on the screen. It means header sent but what headers were sent?
^^ No. Has been discussed earlier. echo '<pre>' . print_r(get_headers('http://your-page.com/'), true) . '</pre>'; PHP: Put the URL of the page you're having problems with there and see what headers you get.
I am getting Fatal Error: Fatal error: Call to undefined function: get_headers() I have also installed Firefox plugin but it's not helping. I am getting long list of headers.
Could you post a screenshot of that list? And also, have a look if there's maybe a white space before the PHP opening tag. <?php
Dear friends thanks for your time and help. I have found a solution. put ob_start(); on the top of the page and ob_end_flush(); should be last line of code. Now its working but main question is still there that what was the problem with header() function.