Forum Moderators: coopster
I have a PHP Function Code, and when i put the following code in my script, the function is executed:
<?php
New();
?>
That works fine. However, i want the value of New(); to be in a header Location. Ive tried the following but it doesnt work:
header( "Location: scripts/index.php?KEY=New();" );
any suggestions would be appreciated.
Cheers
Linda
what i meant was, youre calling this function to get a variable, so I guess at some point in the function you have the variable available.
Put echo $key, or whatever the name of the variable is, inside the function - so when the function is called it will echo the variable.
Sound OK? :)
//added
How about calling the function before the header...and just echoing the variable inside your header.
try doing:
header( "Location: scripts/index.php?KEY=".urlencode(New()) );
if that doesn't work - write the value of KEY in manually as a fixed test - and check that you can read that - maybe it's being passed, but the script the other end has a bug.
and as said above, try:
echo "Location: scripts/index.php?KEY=".urlencode(New());
that will help to isolate the cause of the problem - always the first step in bugquashing
From your first post it looks like New() is doing it's output directly ie.
function New() {
.
.
.
print $keyvalue;
.
.
.
}
In this case that is why you are having a problem. You want to change the function to not print/echo the keyvalue. Instead make the last line of the function read:
return $keyvalue;
Or what every value you want to return. Ensure that this is the last line of the function since the function will exit at that point and any lines after the return will never be executed.
For more information about return see this PHP Manual Page [php.net]