Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to redirect a page in php. But I don't want to use header() function, because it causes so many errors. I want to use an error free method.
Please guide me, how can i do that?
Posted
Comments
Mohibur Rashid 18-Jan-14 1:48am    
Even though you have got your answer, I want to add something here. First of I know what error you are facing. If I am not making mistake you are facing problem with creating header request after sending output. I would suggest you learn how to avoid this issue and work with it. Be cause you will have lots of situation where you would have to send header data without exception. I can see that you are still learning. So, it would be better if you clear this issue than avoiding.

You can use JavaScript outputs by you PHP:

PHP
    echo '<script>window.location="http://abc.com"</script>';
/>


It will redirect your page to http://abc.com.
 
Share this answer
 
v2
Comments
rashidfarooq 26-Oct-11 3:47am    
thanks for the reply.
but if the user javascript is not enabled??
Bun Leap_kh 26-Oct-11 22:07pm    
if javascript is disable, it won't work. but usually, it is enable by default.
you are welcome!
Killzone DeathMan 2-Jan-14 6:06am    
So if javascript is disable, it won't work... Thats boring...
If the user accidentaly type "ESC" (escape), the javascript breaks!
So I think better will be:

echo '<meta http-equiv="refresh" content="0; url=http://example.com/">';

What do you think? :D
Regards,
KZ
rashidfarooq 26-Oct-11 6:08am    
Thanks a lot for answering me.
Member 13630072 23-Jan-18 7:11am    
Hi can you help me how can I make without refreshing page
you can turn on mod_rewrite on Apache and rewrite the URL to the page you want it to be redirected. Have a look here to begin : mod_rewrite[^]

This process is called URL rewriting. Hope this helps, because I cannot think of any other approach to redirect the page :) .


Cheers.
 
Share this answer
 
Comments
rashidfarooq 26-Oct-11 6:08am    
Thanks for Reply. Let me try that.
I.explore.code 26-Oct-11 6:56am    
you are welcome
printf("<script>location.href='errorpage.html'</script>");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900