Jump to content

[SOLVED] How to execute a link in PHP ?


tmyonline

Recommended Posts

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. 

Link to comment
https://forums.phpfreaks.com/topic/63350-solved-how-to-execute-a-link-in-php/
Share on other sites

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.

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

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 :-)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.