Answer the question
In order to leave comments, you need to log in
How to make a conditional redirect in PHP?
Hey! Please help with the task.
Let's say the file file.txt contains the number 70 or 93, it doesn't matter. It is necessary to achieve the result so that a redirect to page2.php occurs when the number 1000 is in file.txt.
Thank you.
Answer the question
In order to leave comments, you need to log in
$file_path = 'file.txt';
$file_redirect_data = '70';
if (file_exists($file_path)) {
$file_content = file_get_contents($file_path);
if ($file_content == $file_redirect_data) {
header('Location: http://www.example.com/page2.php');
exit();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question