valgris Posted January 11, 2012 Share Posted January 11, 2012 Hello I am having another minor issue where I am unable to spot where I am going wrong. The code for my logout button should redirect the user to index.php however I seem to be having an issue with the url. This is on my test server and I am using $url = BASE_URL . 'index.php'; // Define the URL. however the button seems to be taking me to: http://localhost/ICU/localhost/ICUindex.php An I am not quite sure why, the base_url should be localhost/ICU or localhost but the url given out is localhost/ICU/Localhost/ICUindex.php. why is it repeating itself? So where am I going wrong, is it in my understanding of the BASE_URL or something else? As always thank you in advance for any help. Link to comment https://forums.phpfreaks.com/topic/254816-trouble-with-base_url-and-re-directing/ Share on other sites More sharing options...
MrGary Posted January 11, 2012 Share Posted January 11, 2012 If your "index.php" file is in the same folder, why don't you use $url = "./index.php"; Link to comment https://forums.phpfreaks.com/topic/254816-trouble-with-base_url-and-re-directing/#findComment-1306572 Share on other sites More sharing options...
valgris Posted January 11, 2012 Author Share Posted January 11, 2012 Okay that makes so much more sense, I think I need to call it a night. Though I could even use "." However I would still like to know where I went wrong with the BASE_URL, I am going wrong somewhere and for future reference it would be good to know. Thank you MrGary Link to comment https://forums.phpfreaks.com/topic/254816-trouble-with-base_url-and-re-directing/#findComment-1306575 Share on other sites More sharing options...
MrGary Posted January 11, 2012 Share Posted January 11, 2012 BASE_URL isn't a PHP constant, I don't know how it has been defined in your code but I think that it refers to the "URL" to your script which is : "localhost/ICU" So I guess that it may work if you do : $url = "http://".BASE_URL."/index.php"; Link to comment https://forums.phpfreaks.com/topic/254816-trouble-with-base_url-and-re-directing/#findComment-1306576 Share on other sites More sharing options...
valgris Posted January 11, 2012 Author Share Posted January 11, 2012 define ('BASE_URL', 'localhost/ICU'); you are right its down to how I defined the base url I thought the code would work as follows though: Base url = Localhost/icu + /index.php localhost/icu/index.php not localhost/icu/localhost/icu/index.php Link to comment https://forums.phpfreaks.com/topic/254816-trouble-with-base_url-and-re-directing/#findComment-1306582 Share on other sites More sharing options...
kicken Posted January 11, 2012 Share Posted January 11, 2012 Unless a URL begins with http:// or https://, then it is treated as a relative URL. If it begins with a '/' it refers to the root but uses the current domain name/scheme. Otherwise, it is based on your current directory. So your base of 'localhost/ICU' combined with '/index.php' = 'localhost/ICU/index.php' Since it doesn't start with a '/' or a scheme, it is relative to the current directory, which is already http://localhost/ICU. 'http://localhost/ICU' + 'localhost/ICU/index.php' = 'http://localhost/ICU/localhost/ICU/index.php' Link to comment https://forums.phpfreaks.com/topic/254816-trouble-with-base_url-and-re-directing/#findComment-1306700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.