Jump to content

Help with header(location)


lightlydone

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.