tmyonline Posted August 4, 2007 Share Posted August 4, 2007 Guys: suppose I have the following piece of code: If TRUE { do this; } else { go to this page; } In the else clause, is there a function in PHP that I can pass in an URL and make it automatically go to that particular page ? The only PHP function I know for this purpose is the "header" function but it does not always work. Any alternative or suggestions? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/ Share on other sites More sharing options...
dbillings Posted August 4, 2007 Share Posted August 4, 2007 Depends where your putting the conditional. If it is loaded during the page load you could use a meta redirect <meta http-equiv="Refresh" content="5;url=http://www.phpfreaks.com" /> Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315675 Share on other sites More sharing options...
dbo Posted August 4, 2007 Share Posted August 4, 2007 Header is the way to do it... you just have to do it before any other output is sent to the screen. The other alternative is javascript.... but if a user disables javascript then there is nothing you can do to make it go there... thus header is the way to go Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315677 Share on other sites More sharing options...
tibberous Posted August 4, 2007 Share Posted August 4, 2007 Header doesn't always work, but it works like 99% of the time. I can only think of one browser that will not work with header, and even then you have to turn it off. I'd just use header. Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315686 Share on other sites More sharing options...
dbo Posted August 4, 2007 Share Posted August 4, 2007 What do you mean it doesn't always work? Can you give an example? The only time I've not seen it work is if you use it wrong and send data before headers. Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315688 Share on other sites More sharing options...
avillanu Posted August 4, 2007 Share Posted August 4, 2007 Guys I am building a simple form submit. After inserting the data into the DB, I'd like the script to redirect the user to a page. I'm using header('Location: http://www.google.com/'); but obviously it gives me Warning: Cannot modify header information - headers already sent Is there any workaround this? I've been doing some googling and evidently this solution does not work if there is any data sent to the page. Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315697 Share on other sites More sharing options...
dbo Posted August 4, 2007 Share Posted August 4, 2007 The solution is to do your form processing at the top of the page before you send any data. Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315698 Share on other sites More sharing options...
BlueSkyIS Posted August 4, 2007 Share Posted August 4, 2007 To elaborate: Data can't be sent to the browser before header("Location"). If you need to send the user to a page based on the result of some processing, process the data first, then send the user to the location. Don't try to display any information and THEN send the user, because by definition you've already sent the headers and you can't send them a second time. -BSIS Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315705 Share on other sites More sharing options...
tmyonline Posted August 4, 2007 Author Share Posted August 4, 2007 Thanks so much for everyone's response here. I really enjoy this forum. You guys are really active with your prompt reply, I'm very impressed and thankful! I'd like to particularly thank "dbo". Your suggestion is very helpful. The problem I had is that I used server side include to include an upload page at the top of the page. After I moved it down below the header function, yes, it worked as expected and the uploading process also worked as well. Many thanks to everyone and to "dbo" in particular. Have a good weekend :-) Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315707 Share on other sites More sharing options...
avillanu Posted August 4, 2007 Share Posted August 4, 2007 Great thanks Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315708 Share on other sites More sharing options...
dbo Posted August 4, 2007 Share Posted August 4, 2007 Glad to have helped and thanks for the kind words Quote Link to comment https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/#findComment-315709 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.