jdadwilson Posted May 5, 2007 Share Posted May 5, 2007 I have some php code that I want to reference from several pages. I cannot put the code into a function since the calls are from action tags (which only refers to scripts). Therefore, how does one use the Header function to return to the previous calling page? Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/ Share on other sites More sharing options...
neel_basu Posted May 5, 2007 Share Posted May 5, 2007 I didn't understand what you told may be keep that code in my_code.php and then include_once('my_code.php') in all the files Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/#findComment-245969 Share on other sites More sharing options...
BrandonE97 Posted May 5, 2007 Share Posted May 5, 2007 You can maybe use header("Location: ".$_SERVER['HTTP_REFERER']); to redirect to the last page? Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/#findComment-245972 Share on other sites More sharing options...
neel_basu Posted May 5, 2007 Share Posted May 5, 2007 You can maybe use header("Location: ".$_SERVER['HTTP_REFERER']); to redirect to the last page? Its not reliable Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/#findComment-245977 Share on other sites More sharing options...
neel_basu Posted May 5, 2007 Share Posted May 5, 2007 the page1.php will place a cookie page: page1.php (e.g. the last Page Name) and the page2.php would follow the page thats in the Cookie Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/#findComment-245979 Share on other sites More sharing options...
BrandonE97 Posted May 5, 2007 Share Posted May 5, 2007 The variable $_SERVER['HTTP_REFERER'] sets a cookie? What about the other $_SERVER variables? Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/#findComment-245981 Share on other sites More sharing options...
neel_basu Posted May 5, 2007 Share Posted May 5, 2007 The variable $_SERVER['HTTP_REFERER'] sets a cookie? What about the other $_SERVER variables? No I am not talking about $_SERVER['HTTP_REFERER'] What I am telling is page1.php sets Cookie and page2.php reads to cookie to understand whats teh previous page. Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/#findComment-245985 Share on other sites More sharing options...
jdadwilson Posted May 5, 2007 Author Share Posted May 5, 2007 OK, so for a newbie what is the code to do this? Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/#findComment-245992 Share on other sites More sharing options...
jdadwilson Posted May 5, 2007 Author Share Posted May 5, 2007 I didn't understand what you told may be keep that code in my_code.php and then include_once('my_code.php') in all the files The trigger to the code is from an anchor element. Using the href or the onclick both require a script. I would much like to put the code into a function in an include file and have it triggered by the anchor onclick event but I don't see how this can happen. Any ideas... Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/#findComment-245994 Share on other sites More sharing options...
yzerman Posted May 5, 2007 Share Posted May 5, 2007 include.php <?php //this file is included in every page function myFunction() { global $var1, $var2 //do something } ?> your script that you will include the file into <?php include ('include.php'); //include your include file if (!isset($_POST['submit'])) { //if the form has been submitted if ($_REQUEST['action'] == 'dosomething') { //if the form is asking to do something $dosomething = $_REQUEST['action']; //define the variable to be sent to the function myFunction($dosomething); //send your variable to your function to be done } } ?> Link to comment https://forums.phpfreaks.com/topic/50094-solved-header-redirect-to-previous-page/#findComment-246004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.