0

Let me try and explain as best as I can,

I have the following code in my login.php:

if(isset($_SESSION['user'])!="")
{
header("Location: home.php");
}

This ensures that if a user has logged in successfully, the url will always display mysite.com/home.php on all pages, this works fine for all php redirects using href="another_page".

However this does not work for javascript redirects using window.top.location.href="another_page", this instead redirects with the full url name (eg: mysite.com/java_redirected_page) instead of mysite.com/home.php. How can I get javascript redirects to work with headers as well, just like php does.

3 Answers 3

1

use this - window.location.href = 'home.php'; rather than window.top.location.href = 'home.php';

Sign up to request clarification or add additional context in comments.

Comments

0

JavaScript is client side interpreter, it can't change headers from your server, while PHP generates responses from your web server, like Apache or nginx.

So the answer is that you can't change the way javascript redirects.

Comments

0

It looks like you want to have a nice result with your url, the only thing i can think of is MVC.

Never heard of it? Read this link http://code.tutsplus.com/tutorials/mvc-for-noobs--net-10488

Its just a nice way to seperate your Backend from your Frontend and with that your redirects would work nicely.

Sad part about is, you would have to rethink yoru whole page, which is pretty timeconsuming because you would have to restructre everything.

Hope it helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.