freelance84 Posted July 1, 2010 Share Posted July 1, 2010 If you look at the following page, http://customcanvasuk.com/. All the links on it will send you to another directory on that website e.g: http://customcanvasuk.com/contact-us/ That URL will remain in the address bar as I am assuming that within the contact-us/ directory there is another index file. However I am trying to achieve the same thing but without as much success. The index.php in the public_html is a login page. The user enters their details hits login and the details are sent to the login.php. If all is correct the login.php uses header() to redirect them to another page. This was working fine when I had all the files in the public_html, but now it doesn't. if ($row[3] == '1') { header("location:http://www.site.net/adw/"); exit(); } The above results a message from ff saying: The page isn't redirecting properly And the address bar reads: http://www.derep.net/adw/index.php Anybody know why? I want the address bar to read: http://www.site.net/adw/ Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/ Share on other sites More sharing options...
freelance84 Posted July 1, 2010 Author Share Posted July 1, 2010 OK, I've now done a simple test. 1 Within the adw directory i renamed the index.php to something else 2. Then put a new file in named index.html 3. closed the browser and tried to login again. It worked, the exact same header loaded the index.html. I replace the index.php and deleted the index.html, and the once again it could not load. Any ideas? (i know the .php file works just fine) Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1079724 Share on other sites More sharing options...
Psycho Posted July 1, 2010 Share Posted July 1, 2010 Well, there is obviously some problem in that file. Does it work if you access it directly? What is in that file? I would take a look at any header commands it might have. Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1079735 Share on other sites More sharing options...
freelance84 Posted July 1, 2010 Author Share Posted July 1, 2010 Well, this is rather embarrassing, I've just realised a couple of the require_once() lines were still trying to get from the same directory as the index it was reading. Where they should be jumping back one step. I'm gonna change this and it should work. Apologies. Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1079740 Share on other sites More sharing options...
freelance84 Posted July 1, 2010 Author Share Posted July 1, 2010 Failed opening required '/security/login.php' The code to try and require is: require_once '/security/login.php'; I've checked the spelling of the directories and that's fine. The .php file trying to get the login is in the root directory, and the login.php is in "security" which is also in the root. Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1079769 Share on other sites More sharing options...
freelance84 Posted July 1, 2010 Author Share Posted July 1, 2010 Failed opening required '/security/login.php' The code to try and require is: require_once '/security/login.php'; I've checked the spelling of the directories and that's fine. The .php file trying to get the login is in the root directory, and the login.php is in "security" which is also in the root. I solved this via trial and error, and found removing the '/' from in front of the security worked. Would someone be able to tell me what the correct way is to go forward and backward (directory wise) from within the public_html? I can't find it anywhere in my book or on google as i'm assuming this is assumed knowledge, only I don't know it Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1079782 Share on other sites More sharing options...
Psycho Posted July 1, 2010 Share Posted July 1, 2010 I always seem to get these backwards, but with the slash at the beginning of the path it indicates that the path should be relative from the root of the site. Without the slash the path should be relative from the current location/path. If that is not what you are seeing, then it is the opposite. Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1079785 Share on other sites More sharing options...
freelance84 Posted July 1, 2010 Author Share Posted July 1, 2010 index.php is within folder "adw" in the public_html. On load it must require_once a file named "functions.php" directly in the public_html. I've tried using the following: require_once '/functions.php'; but it returns Fatal error: require_once() [function.require]: Failed opening required '/functions.php' Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1079794 Share on other sites More sharing options...
Psycho Posted July 1, 2010 Share Posted July 1, 2010 OK, the "root" for the website (i.e. http://www.mysite.com) is in the public_html, but that is not necessarily the root of the file system! Run this file and you will see where the system root is: echo "<pre>"; print_r(glob('/*')); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1079871 Share on other sites More sharing options...
freelance84 Posted July 1, 2010 Author Share Posted July 1, 2010 Ok, i added the lines to the bottom of the main index (the sites main home/login page) and it returned an array. Number 18 in the array read: [18] => /root I'm not much the wiser: What does this mean exactly? Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1079922 Share on other sites More sharing options...
Psycho Posted July 2, 2010 Share Posted July 2, 2010 Somewhere on the file system ther is a folder named "root". The folder in which THAT folder exists is the actual root. Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1080058 Share on other sites More sharing options...
Cagecrawler Posted July 2, 2010 Share Posted July 2, 2010 When referencing files, it uses the server filesystem. If you start a file reference with a forward-slash, it references the root of the partition (eg. C:\ in windows). If you want it relative to your current location, you need to either drop the initial forward-slash or start it ./. As a test, run getcwd() and look at the output. That is the directory of the script as the server filesystem sees it, rather than how the webserver sees it. For example, if I echo getcwd() in http://www.mysite.com/test.php it gives /home2/[my_username]/public_html since that is where the file is stored on the server. Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1080074 Share on other sites More sharing options...
freelance84 Posted July 2, 2010 Author Share Posted July 2, 2010 Please pardon my not getting this, its really annoying me too. Ok, I echo'd getcwd and it returned: /home2/[my_username]/public_html There is a folder in public_html named adw, therefore a php file echoing getcwd() should look like: /home2/[my_username]/public_html/adw The index.php within adw whose location should be: /home2/[my_username]/public_html/adw/index.php ...requires a file whose location is: /home2/[my_username]/public_html/functions.php What should I be putting in the require_once()? Should it be: require_once (/home2/[my_username]/public_html/functions.php); ?? Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1080180 Share on other sites More sharing options...
freelance84 Posted July 2, 2010 Author Share Posted July 2, 2010 It works! Thanks for all your help! A file in sub-folder test named "test" on public_html contains a file named "test1.php". "test1.php" requires "functions.php" from a sub-folder named "testing" on public_html. The following worked: require_once ('../testing/functions.php'); I'm pretty sure this didn't work before, but it does now. I think there must be some more tangles in the actual index.php I was originally testing. Either way I now understand a lot more on the subject. Thanks once again! Quote Link to comment https://forums.phpfreaks.com/topic/206398-isnt-redirecting-properly/#findComment-1080276 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.