slj90 Posted November 4, 2012 Share Posted November 4, 2012 So I have a header('Location: ') in my script and it works fine if I enter something like header('Location: profile.php ') It will go to http://www.example.com/profile.php But I am trying to make it go to the homepage of the site which is just http://www.example.com. I don't want it to show index.php or default.php. So my question is what do I need to put in header('Location: ') for it to direct back to the homepage http://www.example.com Thanks Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/ Share on other sites More sharing options...
Zane Posted November 4, 2012 Share Posted November 4, 2012 Have you tried adding the http protocol to it? header("Location: http://www.example.com"); Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390213 Share on other sites More sharing options...
trq Posted November 4, 2012 Share Posted November 4, 2012 Your first example is incorrect in the first place. A location header should always be set to a url. To get your second example working: header('Location: http://example.com'); Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390214 Share on other sites More sharing options...
Adam Posted November 4, 2012 Share Posted November 4, 2012 You could also just use: header('Location: /'); Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390215 Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 You could also just use: header('Location: /'); The location header requires a url according to the http spec, so it's always best to provide a complete url. Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390225 Share on other sites More sharing options...
slj90 Posted November 5, 2012 Author Share Posted November 5, 2012 Thanks. I had only tried www.example.com which directed to www.example.com/www.example.com! But with http:// at the front it is working. Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390267 Share on other sites More sharing options...
computermax2328 Posted November 5, 2012 Share Posted November 5, 2012 I was going to say, do you have the write file path. I always keep my pages in a lower folder than my index. So mine would look like: header('Location:../index.php'); Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390272 Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 I was going to say, do you have the write file path. I always keep my pages in a lower folder than my index. So mine would look like: header('Location:../index.php'); This will be the third time I have mentioned this, but the Location header requires a url. Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390277 Share on other sites More sharing options...
computermax2328 Posted November 5, 2012 Share Posted November 5, 2012 This will be the third time I have mentioned this, but the Location header requires a url. Not to step on your toes, but if that is true why does that work? I do it all the time. Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390281 Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 Doing so means you are relying on a broken implementation. Most browsers implement it incorrectly. Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390284 Share on other sites More sharing options...
Adam Posted November 5, 2012 Share Posted November 5, 2012 The location header requires a url according to the http spec, so it's always best to provide a complete url. Ah, I never realised that. Link to comment https://forums.phpfreaks.com/topic/270292-headerlocation-question/#findComment-1390421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.