Jump to content

Archived

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

CloudSex13

Reload Page in a PHP Function

Recommended Posts

is there a reason why the

 

header("location: index.php");

 

doesn't work in php functions?

 

ex.

 

function omg() {
echo "money money.";
header("location: index.php");
}

 

thank you for any help if so!

:]

Share this post


Link to post
Share on other sites

a couple posts above you is a topic with lot's o' information on headers...for headers to work, there cannot be anything parsed to the browser before they are executed..

 

for example,

 

function omg() {
echo "money money.";
header("location: index.php");
}

echo'ing money money is causing the header to fail.

 

look into output buffering when getting involved with headers and such .. will save you many headaches.

 

as well, always have

error_reporting(E_ALL);

at the top of all your scripts when in development mode.  gives you a breakdown of any/all errors that occurred.

Share this post


Link to post
Share on other sites

You can't put any content out to a browser before sending a header;

 

function omg() {
echo "money money.";
header("location: index.php");
}

 

will never work due to the line echo "money money.";

 

function omg() {
//echo "money money.";
header("location: index.php");
}

 

that will work

Share this post


Link to post
Share on other sites

ahhhh.

 

is there another way to do this with data output in a function without having to click another link?

Share this post


Link to post
Share on other sites

why don't you explain what it is exactly that you are trying to do...do you need to redirect or do you just need to return a value?

Share this post


Link to post
Share on other sites

is there another way to do this with data output in a function without having to click another link?

 

The 'headers' redirection wuz also troubling me. What I did wuz simply wrote a small function:

function redirect($loc){
echo "<script>window.location.href='".$loc."'</script>";
}

 

and then

 

function GoHere(){
/*
	Do something here...
*/
redirect('index.php');
}

 

and it worked!

 

Hope this helps.

Share this post


Link to post
Share on other sites

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