next Posted July 15, 2008 Share Posted July 15, 2008 I'm trying to redirect when user is logged out: http://localhost/ahk_php/sidebar_links/logout.php to http://localhost/ahk_php/index.php here's my code, logout.php: <?php session_start(); require_once($_SERVER['DOCUMENT_ROOT'] . '/ahk_php/config.php'); session_destroy(); header('location: ' . $_SERVER['HTTP_HOST'] . '/ahk_php/index.php'); ?> But here instead of: http://localhost/ahk_php/index.php i get: http://localhost/ahk_php/sidebar_links/localhost/ahk_php/index.php Why is it appending instead of replacing url completely? Quote Link to comment Share on other sites More sharing options...
NathanLedet Posted July 15, 2008 Share Posted July 15, 2008 I don't think you would need $_SERVER['HTTP_HOST'] at all if you're just trying to go to /ahk_php/index.php header('location: /ahk_php/index.php'); Quote Link to comment Share on other sites More sharing options...
New Coder Posted July 15, 2008 Share Posted July 15, 2008 infact i think you would need header('location: ../index.php'); Quote Link to comment Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 Your missing the http:// header('Location: http://' . $_SERVER['HTTP_HOST'] . '/ahk_php/index.php'); Quote Link to comment Share on other sites More sharing options...
next Posted July 15, 2008 Author Share Posted July 15, 2008 thorpe, thanks this answers my question perfectly! NathanLedet , nah, it would append that to my current location. New Coder , this was a work around that i was using until now, the problem is that if you change files location it's not going to work anymore. Quote Link to comment Share on other sites More sharing options...
NathanLedet Posted July 15, 2008 Share Posted July 15, 2008 NathanLedet , nah, it would append that to my current location. Actually, ahk_php/index.php would, but since there is a slash in front of it (/ahk_php/index.php) it would be localhost/ahk_php/index.php But, thorpe was right. Glad it's working Quote Link to comment Share on other sites More sharing options...
trq Posted July 15, 2008 Share Posted July 15, 2008 The Location header by definition requires a url, not a relative path. While most times it will work, it shouldn't and some browsers won't like it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.