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';
};
?>
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.
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;
}