Hey everyone,
I have a website where I'm using HTML and PHP together. I'm working on a feature where I want to redirect users to a specific URL based on their selection. So basically, I have a form with several options (let's say options A, B, and C) and when the user submits the form, I want them to be redirected to a different URL depending on the option they selected.
For example, if a user selects option A and submits the form, they should be redirected to "www.example.com/page-a". If they select option B, they should be redirected to "www.example.com/page-b", and so on.
I've been trying to figure out how to achieve this, but I'm struggling with the PHP part. I know how to get the value of the selected option using PHP, but I'm not sure how to use that value to redirect the user to the corresponding URL.
Could someone please guide me on how to implement this functionality? I'd really appreciate any help or suggestions.
Thank you!

Hey there,
I've encountered a similar scenario before, and I might be able to help you out. To redirect users to different URLs based on their selected option, you can use the PHP `header()` function along with an if-else statement.
Here's an example of how you can achieve this:
In this code snippet, the `header()` function is used to send a raw HTTP header to the browser, specifically the "Location" header, which triggers the redirect. The `exit()` function is then used to stop the further execution of the script.
Make sure to place this code snippet before any output is sent to the browser, preferably at the very beginning of your PHP file.
Please note that the `header()` function will only work if no output has been sent to the browser yet. If you encounter any issues, ensure that there are no spaces, newlines, or other characters being outputted before the PHP code block.
I hope this helps! Let me know if you have any more questions.