Wondering Coder
Wondering Coder

Reputation: 1702

infinite loop when redirect

When redirect to my home page I have an infinite loop. For example is http://mydomain.com then when redirect using javascript url = 'home/request_verification' ; window.location = url;

my url now becomes http://mydomain.com/home/request_verfication then http://mydomain.com/home/home/request_verification and so on. It always added home class.

I just used this script

function checkCookie() {
var mob_tel=getCookie("mob_tel");
if (mob_tel!=null && mob_tel!="") {
    //alert("Welcome again " + mob_tel);
    url = "home/test";
    window.location = url;
    //window.location.href('home/checkbalance');
} else {
    set_name("");
}
}

then in my body

<body onload="checkCookie()">
 ...........
 ................
</body>

Help anyone..

Upvotes: 1

Views: 5218

Answers (2)

ilight
ilight

Reputation: 1622

You got to use the absolute path, else the infinite loop continues. So, use

url = "http://mydomain.com/home/test";
window.location = url;

If you do not want to hardcode the root URL ie.,http://mydomain.com, try getting the root directory of the site from the server side like $_SERVER["HTTP_HOST"] in PHP as shown below:

url = "http://"+"<?php echo $_SERVER['HTTP_HOST'];?>"+"/home/test"; (for localhost) and
url = "<?php echo $_SERVER['HTTP_HOST'];?>"+"/home/test"; (for urls already containing http://)

window.location = url;

Upvotes: 1

Blender
Blender

Reputation: 298206

home/test is a relative url. You're probably in need of an absolute url /home/test.

The difference is that home/ looks for home in the current folder, but /home looks for home in the root of your website.

Upvotes: 4

Related Questions