linux1880 Posted January 6, 2010 Share Posted January 6, 2010 hi friends I want to redirect to a different page after few statements in function, how do i achieve this ? also, how important is RETURN for function ? pls help Link to comment https://forums.phpfreaks.com/topic/187490-i-want-to-redirect-to-a-different-page-after-few-statements-in-function/ Share on other sites More sharing options...
PHP Monkeh Posted January 6, 2010 Share Posted January 6, 2010 Providing you haven't output anything to the browser, just edit your function to redirect after the statements you want have been executed, like so: <?php function myFunction() { echo 'some statements'; header("Location: newLocation.php"); echo "these won't be shown as you have been re-directed at the line above"; } ?> As for return, you only use that if you want the function to return a value to a variable. Example: <?php function updateName($name) { return $name . " rocks"; } $myName = "PHP Monkeh"; $newName = updateName($myName); echo $newName; // echo 'PHP Monkeh rocks' ?> Link to comment https://forums.phpfreaks.com/topic/187490-i-want-to-redirect-to-a-different-page-after-few-statements-in-function/#findComment-989979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.