NickG21 Posted January 9, 2007 Share Posted January 9, 2007 is it possible to redirect to a page using the header(); and still keep the variables that the page had just passed? Link to comment https://forums.phpfreaks.com/topic/33484-redirect/ Share on other sites More sharing options...
Cep Posted January 9, 2007 Share Posted January 9, 2007 What variables are we talking here? If they are session variables they should be fine though I have heard that the regular header(); has problems doing this in some circumstances on php.net, Here is a revamped version taken from php.net[code=php:0]function redirector($location) { $sname = session_name(); $sid = session_id(); if (strlen($sid) < 1) { header($location); return; } if (isset($_COOKIE[$sname]) || strpos($location, $sname."=".$sid)!==false) { header($location); return; } else { if (strpos($location, "?") > 0) { $separator = "&"; } else { $separator = "?"; } $fixed = $location . $separator . $sname."=".$sid; header( $fixed ); return; }}[/code]If this isnt what you mean please elaborate Link to comment https://forums.phpfreaks.com/topic/33484-redirect/#findComment-156733 Share on other sites More sharing options...
NickG21 Posted January 9, 2007 Author Share Posted January 9, 2007 i am pretty sure header(); doesn't allow you to pass the session variables back, or at least i don't know how to do it, and i believe that is what i want but wi am not sure how to implement it. here is some of my mailer.php code which validates and if correct mails the form data.[code]if(empty($problem)){ $error[]="Description";}if(count($error) > 0){redirector($location);}ELSE{mail('[email protected]',$subject,$problem,"From: $name <$email>");header("Refresh: 0; URL = http://www.../thankyou.html");}?>[/code]the validation and variables are set and work correctly, i am just unsure of how to incorporate this function, im a little new at PHP if you didn't notice lol thanks Link to comment https://forums.phpfreaks.com/topic/33484-redirect/#findComment-156742 Share on other sites More sharing options...
Cep Posted January 12, 2007 Share Posted January 12, 2007 Ah I see, well first things first you need to ensure there is a session by placing session_start(); at the very top of your scripts.The if you want to pass the variables from your form to the page it redirects to you will have to assign them to session variables. This is very simple,For example if you wanted to pass $error to the page $location, $_SESSION['error'] = $error;Then on your $location form when it loads just check for $_SESSION['error'] by doing something like this,if (isset($_SESSION['error'])) { $error = $_SESSION['error']; } else { $error = ""; }If your not sure about sessions there is a good tutorial here. Link to comment https://forums.phpfreaks.com/topic/33484-redirect/#findComment-158940 Share on other sites More sharing options...
NickG21 Posted January 12, 2007 Author Share Posted January 12, 2007 I have session_start(); at the beginning of the main page that is including the other files, also in the validation.php page. I would be more than willing to not pass any error text back to the form if there was some way i could figure out to just make the top of the page say Errors Were Found, Pleas Fix: and then have those areas turn red or bold. i am just getting so frusterated with this i have been getting help for over a week on the same type of thing and nobody can figure it out with me. Link to comment https://forums.phpfreaks.com/topic/33484-redirect/#findComment-159081 Share on other sites More sharing options...
Cep Posted January 15, 2007 Share Posted January 15, 2007 Post your form code. Link to comment https://forums.phpfreaks.com/topic/33484-redirect/#findComment-161041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.