lightlydone Posted June 22, 2011 Share Posted June 22, 2011 Hi Guys, After many hours research I still can't get my head around redirecting with header(location) and so am hoping someone out there would be kind enough to help me out? Basically i am posting form results to a url and waiting for a response. If the response is yes then i would like to redirect the user to a url that was sent back with the response, otherwise the results are posted to a 2nd url and if the response from that is yes i would like to redirect the user to a url that was sent back with that response etc... etc... <body> <?php if(isset($_POST['submit'])){ $email = $_POST['email']; $title = $_POST['title']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $ip = $_SERVER['REMOTE_ADDR']; $id = $_SESSION['id']; $date = date("Y-m-d"); $time = date("H:i:s"); //DO CURL STUFF if ($response == "true"){ $xml = new SimpleXMLElement($leadResult); $url = $xml->Redirect; header("Location: $url"); // if i get a positive response i want to redirect } else { //DO MORE CURL STUFF if ($response == "true") { $xml = new SimpleXMLElement($leadResult); $url = $xml->Redirect; header("Location: $url"); // if i get a positive response i want to redirect } else { ($response == "false"); } } // WRITE RESULTS TO DATABASE } ?> </body> I realise that this won't work, i'm just not sure why it won't work and, more importantly, how to make it work. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 22, 2011 Share Posted June 22, 2011 Please be more specific. what exactly is not working? what error are you getting? Does it do nothing? does it give an error? does it redirect to the wrong page? header("Location: $url"); is fine, as long as there has not been any output yet, otherwise you'll get an error saying "headers already sent" or something of the sorts. are you sure $url is the correct address? Where is that variable coming from? (I don't see it in the code) echo $url just to be make sure it's correct. or change it to header("Location: http://www.google.com"); just to test. Also, consider tidying the curl stuff and the redirect into a function, since you'll be calling it several times until it evaluates to TRUE. turn on php errors and post error here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.