Jump to content

PHP site not working after host migration - Urgent


lee_sov

Recommended Posts

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");

?>
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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");
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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


 
  

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

$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?

Link to comment
Share on other sites

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 by RedInjection
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.