-4

Afternoon! I am trying to check if a URL received from a post variable exists and if it does send the user there. If not redirect elsewhere... I wrote this but for some reason Is not working,

Any ideas? Cheers

<?php>
$file = $_POST["code"];
$file_headers =                   
@get_headers('http://example.co.uk/' $file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
/* does not exist
header('Location: http://example.co.uk/?exists=false');
echo $file 'not found';
}
else {
/* exists
header('Location: http://example.co.uk/' $file);
echo $file 'found';
};
?>
user1949366
  • 465
  • 2
  • 6
  • 17
  • check here http://stackoverflow.com/questions/2280394/check-if-an-url-exists-in-php – axel Jan 04 '13 at 18:43
  • Please post code that is without syntax errors unless you ask about the error message itself. Thank you for choosing flying with us. – hakre Jan 07 '13 at 17:45

2 Answers2

4

You are using comments wrong. It is // and not /* when doing a one line comment.

As you can see from the markdown display, the whole end of your code is currently commented out and your script will have errors.

Naftali
  • 144,921
  • 39
  • 244
  • 303
0

Try do it that way:

$file = 'http://www.domain.com/somefile.jpg';
$file_headers = @get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
    $exists = false;
}
else {
    $exists = true;
}
akuzma
  • 1,592
  • 6
  • 22
  • 49