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? Link to comment https://forums.phpfreaks.com/topic/114860-solved-headerlocation/ 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'); Link to comment https://forums.phpfreaks.com/topic/114860-solved-headerlocation/#findComment-590656 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'); Link to comment https://forums.phpfreaks.com/topic/114860-solved-headerlocation/#findComment-590660 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'); Link to comment https://forums.phpfreaks.com/topic/114860-solved-headerlocation/#findComment-590663 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. Link to comment https://forums.phpfreaks.com/topic/114860-solved-headerlocation/#findComment-590692 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 Link to comment https://forums.phpfreaks.com/topic/114860-solved-headerlocation/#findComment-590720 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. Link to comment https://forums.phpfreaks.com/topic/114860-solved-headerlocation/#findComment-590770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.