PHP debugging

Status
Not open for further replies.

Kracov

Ars Praetorian
413
Hello all. My webhost recently upgraded the php code and so it rendered my website inaccessable. I don't know php myself and I tried to use firebug and firephp but I could not figure out how to use it. I was wondering if someone could debug the php for me and fix it perhaps. The php code is just to redirect mobile users to a smaller version of my site.

My website: http://kracov.org

Just the php script:
Code:
<?php
if (strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), 'MSIE') !== FALSE) {
    $url = urlencode(urldecode($_GET['url']));
    header('Location: http://kracov.org/home.html?redirect=' . $url . '');
    }
    ?>

<?php
$useragent=$_SERVER['HTTP_USER_AGENT'];
if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4)))
header('Location: http://m.kracov.org');
?>
 

MarkLT1

Ars Tribunus Militum
1,615
Subscriptor
One possibility is that they configured the server to require the .php5 suffix (I had a web host that did this, and it made things very difficult). This can be changed via a .htaccess file if you have permissions to use .htaccess file. But if you only have one file, you can just change it from {filename}.php to {filename}.php5

edit2: also, if you have access to error logs from the web server, this will make troubleshooting much easier.

edited: for some reason I was thinking that this was the tag (e.g.: <?php5 ) instead of the file suffix.
 

MarkLT1

Ars Tribunus Militum
1,615
Subscriptor
[url=http:/civis/viewtopic.php?p=27111573#p27111573:2zu0748b said:
Kracov[/url]":2zu0748b]what do i put inside the htaccess file? I renamed the html file to .php5 but i still get a 500 error

If renaming to .php5 didn't fix it, then the .htaccess file wont help.

I'd recommend getting in touch with your webserver tech support. The php you posted is valid php5 code, so it should not be throwing an internal server error.
 

Vivi The Mage

Smack-Fu Master, in training
90
Been a while since I posted on here, but I am the host in question.

What I ended up doing was going from PHP 5.3.28 to 5.4.29, so we could get on a supported version. These script seems to be the only issue out of the hunderd or so PHP scripts that exist on this box.

With my little PHP knowledge, is there anything I can do on the backend to allow his script to run as it sits now?

I am kind of stumped here as well!
 

Kracov

Ars Praetorian
413
Could the contents of the .htaccess file be conflicting with the new php version?

Code:
ErrorDocument 404 http://kracov.org/404.html

RewriteEngine On
# Check for mime types commonly accepted by mobile devices
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ http://m.kracov.org%{REQUEST_URI} [R,L]

Vivi: have you tried to get the server error log?
 

Vivi The Mage

Smack-Fu Master, in training
90
ohhh, this is useful:

Code:
[Fri Jun 27 10:16:44 2014] [error] [client x.x.x.x] malformed header from script. Bad header=<br />: index.php5
[Fri Jun 27 10:16:44 2014] [error] [client x.x.x.x] File does not exist: /home/kracovor/public_html/500.shtml
[Fri Jun 27 10:16:44 2014] [error] [client x.x.x.x] File does not exist: /home/kracovor/public_html/favicon.ico

looks like the break in the header is a problem?
 

Vivi The Mage

Smack-Fu Master, in training
90
[url=http:/civis/viewtopic.php?p=27118063#p27118063:27cwjfb2 said:
Kracov[/url]":27cwjfb2]No, besides I changed it according to the forum's recommendation. Changed it back to .php, still 500 error.

and now we get:

Code:
[Fri Jun 27 10:32:04 2014] [error] [client x.x.x.x] malformed header from script. Bad header=<br />: index.php
[Fri Jun 27 10:32:04 2014] [error] [client x.x.x.x] File does not exist: /home/kracovor/public_html/500.shtml
 

Schluppy

Ars Tribunus Militum
2,486
You need to exit after redirecting to prevent any subsequent code from executing. ie:

Code:
header('Location: http://kracov.org/home.html?redirect=' . $url . '');
exit;

Also, the additional single quote you're concatenating is unnecessary and may be the source of the error.

Code:
header('Location: http://kracov.org/home.html?redirect=' . $url);
exit;

And, turn on error reporting when debugging.

Code:
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
 
i may have found a solution. everywhere i looked about malformed headers, it always happened when someone upgraded to PHP version 5. it has to do with having to rename a file on the server side. "php.old"

Try doing:

ln -s /usr/bin/php-cgi /usr/bin/php

or

cp /usr/bin/php-cgi /usr/bin/php

You may already have a php binary in that directory so you may need to rename it:

mv /usr/bin/php /usr/bin/php.old
 
Status
Not open for further replies.