0

@themask Hello and thanks for your help, I have tosed the php and now have just this code

<script>
document.forms[0].onsubmit = 
    function() {
       var to = document.getElementById('myInput').value;
       var ajax = new XMLHttpRequest; 
       ajax.onreadystate = function() {
            if(this.readyState == 4 && this.status != 404) {
                window.locaiton.replace(to);
            } else {
                window.location.replace('http://www.mysite.com/incontinence/protective_underwear/presto_protective_underwear/');
            }
    }; 
    ajax.open('GET',to);
    ajax.send(null);
};
      </script>
      <form onsubmit="location.href='http://www.mysite.com/coupons/' + document.getElementById('myInput').value; return false;" >
  <input type="text" id="myInput" />
  <input name="Submit" type="submit" id="Submit" />
</form>

But it is still sending me to incorrect urls if a bad code is used. Its like it is skipping the java all together.

Any additional help would be great.

Thank you, Micah

Thank you, Micah

2 Answers 2

2

Try using get_headers()

$headers = get_headers('http://www.activelifemed.com/incontinence/protective_underwear/presto_protective_underwear/')
if($headers[0] == 'HTTP/1.1 200 OK'){
  //exists
}
else{
  //doesn't exist
}

http://www.php.net/manual/en/function.get-headers.php

Sign up to request clarification or add additional context in comments.

2 Comments

I think best check if HTTP CODE is different of 404
@The Mask Hello, I am still lost. I have thrown out the php and now have
0

You can make this using JavaScript:

document.forms[0].onsubmit = 
    function() {
       var to = document.getElementById('myInput').value;
       var ajax = new XMLHttpRequest; 
       ajax.onreadystate = function() {
            if(this.readyState == 4 && this.status != 404) {
                window.locaiton.replace(to);
            } else {
                window.location.replace('http://www.mysite.com/incontinence/protective_underwear/presto_protective_underwear/');
            }
    }; 
    ajax.open('GET',to);
    ajax.send(null);
};

1 Comment

@micah, you should not edit someone's answer to comment on something. You can either add a comment or edit your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.