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
Share on other sites

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

Link to comment
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.