lee_sov Posted November 5, 2015 Share Posted November 5, 2015 HI, so as the title suggests, this website has been moved to a new host & since then it doesnt work, - the homepage loads fine, but we cannot browse to any of the other pages on the site. When we try, we just receive the 404 file or directory not found error. The only difference on the host is the PHP version, - now on 5.3.28 where as it was 5.2.13, which was working fine. The code for the index.php file is below, hopefully its a simple change that needs to be made to get it back up & running, but I'm not sure what. This has now been down over a week so its pretty urgent: <?php $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } $pageURL = explode('?404;', $pageURL); $pageURL = $pageURL[1]; $pageURL = explode(':80/', $pageURL); $pageURL = $pageURL[1]; $c = $pageURL; if(empty($c)){$c="home";} if(!file_exists("$_SERVER[DOCUMENT_ROOT]./kf.pages/$c.php")){$c = "404";} if($c=="home"){include("$_SERVER[DOCUMENT_ROOT]/kf.seg/header.php");}else{include("$_SERVER[DOCUMENT_ROOT]/kf.seg/intheader.php");} include("$_SERVER[DOCUMENT_ROOT]/kf.pages/$c.php"); include("$_SERVER[DOCUMENT_ROOT]/kf.seg/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/ Share on other sites More sharing options...
ginerjm Posted November 5, 2015 Share Posted November 5, 2015 1 - Is DOCUMENT_ROOT a constant that is declared somewhere? 2 - Do you have php error checking turned on so that you can see an "new" warnings or notices that may be happening with the new versions? Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525674 Share on other sites More sharing options...
lee_sov Posted November 5, 2015 Author Share Posted November 5, 2015 1 - Is DOCUMENT_ROOT a constant that is declared somewhere? 2 - Do you have php error checking turned on so that you can see an "new" warnings or notices that may be happening with the new versions? 1 - I don't think so, what can I change this to? 2 - Again no, how can I turn it on & perform checks? Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525680 Share on other sites More sharing options...
ginerjm Posted November 5, 2015 Share Posted November 5, 2015 1 - Put your programmer to work on it? 2 - Read my signature Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525702 Share on other sites More sharing options...
lee_sov Posted November 5, 2015 Author Share Posted November 5, 2015 Thanks, but programmer not available that's why I'm trying to do it (with basic/limited php knowledge)! The code all looks OK to me & was working a few days ago on the previous host so I'm guessing it's just a small change that needs to be made to be able to browse the other site pages from the home page? If anyone can help it would be much appreciated. I will add the error checking code tomorrow & see what that shows. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525703 Share on other sites More sharing options...
cyberRobot Posted November 5, 2015 Share Posted November 5, 2015 1 - Is DOCUMENT_ROOT a constant that is declared somewhere? DOCUMENT_ROOT is likely just referring to the standard index available through $_SERVER. http://php.net/manual/en/reserved.variables.server.php Since the array variable ($_SERVER) is used within a double quoted string, the quotes around the index are not required. I also ran a quick test and creating a constant with that name doesn't seem to affect the array variable. At least is doesn't on my web server. Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525705 Share on other sites More sharing options...
cyberRobot Posted November 5, 2015 Share Posted November 5, 2015 It seems odd that there is a dot after the DOCUMENT_ROOT variable here: if(!file_exists("$_SERVER[DOCUMENT_ROOT]./kf.pages/$c.php")){$c = "404";} But not here: include("$_SERVER[DOCUMENT_ROOT]/kf.pages/$c.php"); Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525706 Share on other sites More sharing options...
lee_sov Posted November 5, 2015 Author Share Posted November 5, 2015 It seems odd that there is a dot after the DOCUMENT_ROOT variable here: if(!file_exists("$_SERVER[DOCUMENT_ROOT]./kf.pages/$c.php")){$c = "404";} But not here: include("$_SERVER[DOCUMENT_ROOT]/kf.pages/$c.php"); I noticed that too, & tried taking the dot out, but it made no difference. Would removing the quotes around the index help, as I thought although not required, it wouldn't cause this problem? Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525707 Share on other sites More sharing options...
cyberRobot Posted November 5, 2015 Share Posted November 5, 2015 Would removing the quotes around the index help, as I thought although not required, it wouldn't cause this problem? It likely won't make a difference, but you would basically change references like this include("$_SERVER[DOCUMENT_ROOT]/kf.pages/$c.php"); To this include("{$_SERVER['DOCUMENT_ROOT']}/kf.pages/$c.php"); Or this include($_SERVER['DOCUMENT_ROOT'] . "/kf.pages/$c.php"); Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525710 Share on other sites More sharing options...
lee_sov Posted November 5, 2015 Author Share Posted November 5, 2015 Is there a way of putting an absolute path in, for example? This sounds a simple issue that it won't link to different pages but I just can't work out what's wrong? Could it be something on the host that's wrong? Does the format of the code all seem compatible with php 5.3, as from what I can work out that's the only difference. Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525711 Share on other sites More sharing options...
cyberRobot Posted November 5, 2015 Share Posted November 5, 2015 Did you get a chance to enable all errors and warnings, as suggested by ginerjm? That should hopefully give you a clue if anything is out of date. Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525712 Share on other sites More sharing options...
lee_sov Posted November 6, 2015 Author Share Posted November 6, 2015 So I enabled the error checking today & the result shown is as below: Notice: Undefined offset: 1 in D:\HostingSpaces\...\wwwroot\index.php on line 17 Notice: Undefined offset: 1 in D:\HostingSpaces\...\wwwroot\index.php on line 19 which relates to the following lines: $pageURL = $pageURL[1]; $pageURL = $pageURL[1]; Any ideas what would be wrong here or need changing? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525787 Share on other sites More sharing options...
lee_sov Posted November 6, 2015 Author Share Posted November 6, 2015 I've changed: $pageURL = $pageURL[1]; to if ( ! isset($pageURL[1])) { $pageURL[1] = null; } $pageURL = $pageURL[1]; Which removes the warning notice, but the pages still cannot be accessed from the home page so the error still persists!! I'm lost now! Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525789 Share on other sites More sharing options...
cyberRobot Posted November 6, 2015 Share Posted November 6, 2015 So I enabled the error checking today & the result shown is as below: Notice: Undefined offset: 1 in D:\HostingSpaces\...\wwwroot\index.php on line 17 Notice: Undefined offset: 1 in D:\HostingSpaces\...\wwwroot\index.php on line 19 It seems like the issue has to do with the code assuming that $pageURL always contains "?404;" and ":80/". Since it sounds like that's an issue with the new server setup, you'll want to make sure the URL contains those values before trying to split a string based on the values. Try changing this $pageURL = explode('?404;', $pageURL); $pageURL = $pageURL[1]; $pageURL = explode(':80/', $pageURL); $pageURL = $pageURL[1]; To this var_dump($pageURL); //<-- debugging code; remove when done if(strpos($pageURL, '?404;') !== false) { $pageURL = explode('?404;', $pageURL); $pageURL = $pageURL[1]; } if(strpos($pageURL, ':80/') !== false) { $pageURL = explode(':80/', $pageURL); $pageURL = $pageURL[1]; } var_dump($pageURL); //<-- debugging code; remove when done Note: the calls to var_dump() are just there so that you can see how the URL looks before and after the code executes. They can be removed at any time. Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525807 Share on other sites More sharing options...
lee_sov Posted November 6, 2015 Author Share Posted November 6, 2015 me page doesnt work when I change that, - just get a 404 error... Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525810 Share on other sites More sharing options...
RedInjection Posted November 6, 2015 Share Posted November 6, 2015 $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } Can I check why you need to see if HTTPS? Do you use individual pages for encryption or everything? I am just asking because you could be able to remove some of this code as it's unnecessary and add a rule in .htaccess? Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525812 Share on other sites More sharing options...
RedInjection Posted November 6, 2015 Share Posted November 6, 2015 (edited) Create a .htaccess file RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://yourwebsite.com/$1 [R,L] PHP <?php if(empty($c)){$c="home";} // not sure what this is? if(!file_exists("kf.pages/$c.php")){$c = "404";} if($c=="home"){include("kf.seg/header.php");}else{include("kf.seg/intheader.php");} include("kf.pages/$c.php"); include("kf.seg/footer.php"); ?> Can I check what are you trying to do with $c="home"; ? Edited November 6, 2015 by RedInjection Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525815 Share on other sites More sharing options...
RedInjection Posted November 6, 2015 Share Posted November 6, 2015 Also tested this $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } $c = $pageURL; print $c; if(!file_exists("404.php")) if($c=="home"){include("header.php");}else{include("kf.seg/intheader.php");} include("kf.pages/$c.php"); include("kf.seg/footer.php"); Create a 404 page or add a rule htaccess to say its missing Quote Link to comment https://forums.phpfreaks.com/topic/299224-php-site-not-working-after-host-migration-urgent/#findComment-1525820 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.