I want to redirect users to a mobile version of my website.
The redirect works fine, however the php variables are not passing.
I am using the following:
<script>
if ($(window).width() < 480 || $(window).height() < 480) {
var searchproducts = "<?php $_GET['search']?>";
var category = "<?php $_GET['cat']?>";
var page="http://m.website.com/search.php?search="+searchproducts+"&cat="+category;
document.location.href=page;
}
</script>
I have also tried:
<script>
if ($(window).width() < 480 || $(window).height() < 480) {
window.location.replace("http://m.website.com/search.php?search=<?php $_GET['search']?>&cat=<?php $_GET['cat']?>");
}
</script>
Can anyone help?
Thanks
You need to add the echo
statement..
var searchproducts = "<?php echo isset($_GET['search']) ? $_GET['search'] : 'Nothing'; ?>";
var category = "<?php echo isset($_GET['cat']) ? $_GET['cat'] : 'Nothing'; ?>";
Also, use an isset
construct as shown.
You are not echoing the variables. Like this:
<?php echo $_GET['cat']?>