Basically my shirt e-commerce website won’t redirect to my html website. Whenever I try to click on the virtual try on button next to the shirt, it doesn’t redirect me to the page instead it just loads and refreshes the current page. Any tips?
Here is my code:
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="get">
<input type="hidden" name="product_id" value="124">
<input type="submit" value="Virtual Try ON" name="form_virtual_try_on">
</form>
<?php
$product_id = $_GET['product_id'] ?? '';
switch ($product_id) {
case '124':
$text = 'Virtual Try On';
$link = 'vton_ls.html';
break;
default:
$text = '';
$link = '';
break;
}
if (isset($_GET['form_virtual_try_on'])) {
$product_id = $_GET['product_id'];
if ($product_id == '124') {
header('Location: vton_ls.html');
exit;
} else {
echo "Invalid product ID";
}
}
?>
<div class="share">
<?php echo LANG_VALUE_58; ?> <br>
<div class="sharethis-inline-share-buttons"></div>
</div>
I tried GET, switch case, and redoing all my codes from scratch but it doesn’t seem to work.
3
Answers
You already added the header and pls add anchor tag too
header (‘Location: vton_ls.html’);
you’re trying to link from an HTML page to a PHP page, you can use an anchor tag like this:
By simply adding little snippets of code rather than the actual full page it is potentially easy to misinterpret what you are trying to do and why things are going awry so if the following is not correct I apologise.
Given a testing target page (
vton_ls.html
) and an interpretation of the aboveBy clicking the button the form submits to the same page where the GET request is processed to build the new url that redirects to your
html website
If you fail to complete this, you’ll probably see an error message that tells you “headers are already sent.” The error might not be a massive one — the header function is so finicky that a single white space can prompt this error.
header(‘Location: http://www.example.com/‘);
exit;
?>