why i see white page when upload my php on my host? - php

I designed my site with php and it works fine on wamp server,but when i uploaded my PHP site to my host and i went to my site address i saw only white page.(it show only page title in correct way!)
I used some include sentence with pointing to parent directory with using two point "../"
Do you think that this can be cuse of problem?
Please recommend me a way to find error and debug it.
This is my first page code:(i should mention that for example when i go to content.php it display correct)
<?php
include("includes/classes/mysession.php");
$ms=new Mysession("turkish_az","home");
$ms->setCurrentPage("home");
if(isset($_GET["slc_language"])){
$ms->setLanguage($_GET["slc_language"]);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="includes/css/style_header.css" rel="stylesheet" type="text/css" />
<link href="includes/css/style_home.css" rel="stylesheet" type="text/css" />
<link href="includes/css/syle_footer.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="includes/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$("#slc_language").val("<?php echo($ms->getLanguage());?>");
$("#form_search").submit(function(e) {
var data=$(this).serialize();
e.preventDefault();
$.ajax({
type: 'POST',
url: 'pages/meaning/mean.php',
data: data,
success: function(resp){
$("#resultpart").html(resp);
}
});
});
});
</script>
</head>
<body>
<div id="container">
<?php require("pages/header/header.php"); ?>
<?php require("pages/main/content.php"); ?>
<?php require("pages/footer/footer.php"); ?>
</div>
</body>
</html>
i checked hedear & content & footer php files:
1-The header show white page like first page
2-The content is show correct
3-the footer show half correct but has an error:
Fatal error: Call to a member function getLayoutName() on a non-object in /home/u998326115/public_html/pages/footer/footer.php on line 14

Find in your hosting docs how you can see error logs. It can be file error_log in script folders, some files in folder logs or you can access to logs in hosting control panel (CPanel, for example). Or you can ask your hosting support.
Turn on error display and set error level to E_ALL for all your scripts. You can make this in .htaccess file or in your code. Ask your hosting support team how you can make this better.

You only have two bits of php, some above the title and some below.
Since you are getting the page title, we can conclude it's the lower php which causes the page to not load.
Presumably the paths to the files you're including are not right. Try changing the very first "include" to "require", do you now stop getting the title? In which case your paths are wrong.
Add this to the very top
error_reporting(E_ALL);
ini_set('display_errors', '1');

Related

CSS and JS won't load even when in same directory as index.php

I feel like I must be missing something very obvious, because I've never had this happen before!
I'm running a local PHP server running the following command:
php -S localhost:8888 index.php
When I go to the URL, the HTML and all the php code run just fine.
However, whenever I add a script tag to add JS in the header, I recieve the following error:
Uncaught SyntaxError: Unexcepted token <
And when I attempt to add a CSS file I get this error:
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8888/assets/style.css".
No matter whether I try and include the header by using PHP include:
<?php include("../includes/layouts/header.php"); ?>
Or directly adding a header and these imports in index.php, I always receive these errors.
My hunch was it was an issue with the directory tree. But I've even placed the CSS and JS files in the same directory as index.php and have added the header code to index.php, yet I still get these errors.
Header code
<!DOCTYPE html Public "HTML TEMPLATE">
<html lang="en">
<head>
<title>Title</title>
<link rel="stylesheet" href="style.css" media="all" title="no title" type="text/css" charset="utf-8">
<script src="script.js"></script>
</head>
<body>
<div id="header">
<h1>Header</h1>
</div>
script.js:
$( document ).ready(function() {
console.log( "ready!" );
});
Console log of errors:
Adding an image of my current project structure:
you should used / at the start of the path. as per your update question your path become /public/assets/style.css. but again i recommend you should used best way
link rel="stylesheet" href="/public/assets/style.css" media="all" title="no title" type="text/css" charset="utf-8">
<script src="/public/assets/script.js"></script>
Some more information about absolute path and relative path
If the path is built starting from the system root, it is called
absolute.
If the path is built starting from the current location, it is called
relative
The best way: you should create base url like in config.php file
define('BASE_URL', 'http://example.com');
and you can used like this
<?php
include('config.php');
?>
<link rel="stylesheet" href="<?php echo BASE_URL; ?>/styles.css" />

seo effect - include file with <html> tag inside

Maybe its a stupied question but i didnt fild any answer for it,
If i have file with the html tag head tag&meta.. and I include him in all my web page, its effect the seo of the site?
I have file named "start_html.php" that have this code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="bla bla.">
<meta name="keywords" content="bla bla">
<meta name="author" content="bla">
<title>bla bla</title>
<!-- CSS: -->
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<!-- JavaScript -->
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
I start every page with this line: <?php include('start_html.php'); ?>
When i check for code error on w3c validator its says that i dont have those tags so the page is not coded good.
If the code from that file is not being displayed in your web page then obviously your PHP code is incorrect and that file is not being included. You need to make sure you have error reporting on and displaying all errors as this will catch this for you.
See this StackOverflow question for how to enable error reporting.
You should have these meta and title tags on all your pages, so including them from PHP is certainly not a bad idea.
However, if the W3 validator tells you these tags aren't there, you should check your output. Perhaps start by 'show source code' in your browser, and see if the tags appear there.
If you try to send your source file for validation, where you have:
<?php include('start_html.php'); ?>
Of course you will get the expected result - no tags, because the source file must be parsed and handled by PHP.
You can give a working link for validation, or copy output in your browser after execution, save the file and send it.

Random whitespace in a PHP page (the client received page, but not the client-received source-code), but only when I use an include()

Ok, I am having the weirdest problem in history. I am making a website that works perfectly in HTML, but is having some REALLY odd behaviour when rendered from PHP - despite having the EXACT SAME client source code (I literally went through it character by character).
At first I thought I'd messed up something in my 'functions.php' file that I'm including, but I don't get any errors, and when I copy&paste the contents of that file into the place where the include('functions.php'); line is, the problem disappears.
Here's my code (with some HTML removed, this is all of the PHP):
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
include 'functions.php';
$footer = file_get_contents('footer.txt');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Removed</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<link type="text/css" rel="stylesheet" href="css/jquery-ui-custom.css" />
<link type="text/css" rel="stylesheet" href="css/main.css" />
</head>
<body>
<div id="header">
<div id="headerContent">
<div id="logo">
</div>
<?php
echo trim(GetNav());
?>
</div>
</div>
<div id="content">
<?php
$NumberOfNewsItems = 2;
echo trim(GetNews($NumberOfNewsItems));
?>
</div>
<?php
echo trim($footer);
?>
</body>
</html>
The functions GetNav and GetNews grab info from the database so I'm not going to show the code from them, plus, as I mentioned earlier, if I don't include the file but instead copy it's contents to the place I make the include call then most of the whitespace disappears (there's still some where the 'echo $footer' call is.
Basically, when you look at the source code, everything looks fine. Where stuff gets incredibly strange is when you hit F12 to look at the dev tools and the elements tab shows a whole bunch of extra whitespace (surrounded by double quotes) immediately after the tag (which impacts the look of the site) as well as between the footer and content Divs (which again, impacts the look of the site).
Also in this view, all of the tags from the are below the first set of white-space and the tag is empty (eg: <head></head>).
The source code looks fine (and if I copy and paste the source code into a HTML file it works flawlessly) and I have to admit that this has me tearing my hair out.
Please help me Obi-Wan-Kenobi, you're my only hope (yes, I love Star Wars, although I wish they'd made more than three movies).
P.S. This might be mega-obvious, but I'm a .Net developer doing this for a family member in my spare time (also it's fun to learn new languages, even ones overly fond of the $ sign), so apologies in advance if I'm the world's biggest newb.
EDIT: What I see in the dev tools is this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
"
"
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Removed</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<link type="text/css" rel="stylesheet" href="css/jquery-ui-custom.css" />
<link type="text/css" rel="stylesheet" href="css/main.css" />
Etc.
EDIT2: Just to be clear, I don't care what the dev tools show, it's just that I'm getting whitespace showing where those quotes are on the actual website, other than that everything is perfect.
EDIT3: Also, the whitespace cannot be clicked on with the element selector and selecting the whitespace in the element tab does not highlight anything on the website. Deleting it in the element tab however DOES fix the website (until it is reloaded obviously), but obviously doesn't help me with my problem.
Try removing the ?> in your functions.php file and no blank rows after the code. And is the functions.php in the same directory as the main file?
And just a tip, include a footer.php instead of file_get_content :-)
I wasn't able to fix this in a way that satisfies me, but here's the workaround that I implemented:
I removed the include from the header entirely and broke up functions.php into one file per function and just included them where they needed to be called.
This alleviated my problem, although it's not ideal. Glad I don't have to use PHP on a daily basis :).
I had the same issue, on the console the source of the html looked like :
By checking the encoding some files were encoded with utf-8 with bom and some with big5. By saving those file to utf-8 ( without bom) solved the issue for me.
I have used Sublime Text 2 with the EncodingHelper from the package manager to see the current file encoding.
Hope it helps.

Very simple Javascript partial page refresh calling a .php page not working

I've combed the internet for a few hours and still cannot make this simple example work. I hope somebody can assist me. I'm trying to use Javascript to display the contents of a php file. The display should be refreshed often as ultimately it will be used to display text matches from a MySql db that match the characters entered in a search bar (similar to Google's search bar). I'll use setinterval for that but I am not there yet. My issue is that I have minial javascript/AJAX experience and just cannot make it work. I've dumbed it down to a bare bones request and still cannot make it work. Please suggest what isn't working:
The index.html where the content should be viewable is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
</head>
<body>
<script type="text/javascript">
$().ready(function() {
$("#dynamic").load("blasty.php");
});
</script>
<div id="dynamic"></div>
</div>
</body>
</html>
And blasty.php contains:
<?php
echo "hello cruel world!";
?>
Thanks in advance!
Make sure your blasty.php file is on the same domain.
Also, to help debug javascript, right click in Chrome or Firefox and go Inspect Element. Then go to the Console window and it will display most errors.
I also recommend this youtube video about javascript. I it helped me bridge the gap on some javasrcipt gotchas. http://www.youtube.com/watch?v=ljNi8nS5TtQ
Here is a link about debuggers: https://developers.google.com/chrome-developer-tools/
As #Explosion Pills said, FireFox's Firebug is another great option. I will use both to help debug javascript. Firebug is nice because under the Net tab it will display the acutal http requests as they happen in the background, with the params, response, header info, etc.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$("#dynamic").load("blasty.php");
});
</script>
<div id="dynamic"></div>
</div>
</body>
</html>
You are missing the document variable in the $().
<script type="text/javascript">
$(document).ready(function() {
$("#dynamic").load("blasty.php");
});
</script>
Visually that's the only issue I see.
I use $.get instead of $.load.
Try something like this:
$.get("blasty.php",
{ nbRandom: Math.random() },
function(data){
$("#dynamic").html(data);
});
nbRandom is to prevent caching in IE.
Use Firebug to make sure there is a response from the AJAX and go from there.

PHP + JQuery - How to use these two together? Please see my example

I have a php based website. As in, all of the pages html is output via php.
Here is a simple example:
<?php
ob_start();
$pageStart = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MY WEBSITE PAGE</title>
</head>
<body>
<p>CONTENT</p>
</body>
</html>
';
echo $pageStart;
exit;
?>
What i would like to do is make use of some jquery in this page.
So naturally my first attempt was to include the script inside of the php variable like so:
<?php
ob_start();
$pageStart = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var datefield=document.createElement("input")
datefield.setAttribute("type", "date")
if (datefield.type!="date"){ //if browser doesn't support input type="date", load files for jQuery UI Date Picker
document.write('<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />\n')
document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"><\/script>\n')
document.write('<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"><\/script>\n')
}
</script>
<script type="text/javascript">
if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget:
jQuery(function($){ //on document.ready
$('#birthday').datepicker();
})
}
</script>
</head>
<body>
<p>CONTENT</p>
</body>
</html>
';
echo $pageStart;
exit;
?>
Now, I use dreamweavers code editor, which due to the syntax highlighting feature, will point out the masses of syntax errors produced in this.
So i at first attempted to slash out these errors. This failed.
So i tried changing the "s to 's, and visa versa, until the errors were gone. This failed too as it seems the script will not validate in this manner.
So i read a few tutorials, and found this one:
JavaScript and PHP may each bring great potential to any Web development effort, but they don't always play nice together. Read about the problems.
And the way I understand it, is that you'd need to include the js rather than have it as part of your php directly.
So have a file called page.php and another called jquery.php. So I decided to try and modify this idea to suite my problem.
So i started with something like this - index.php:
<?php
ob_start();
$pageStart = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MY WEBSITE PAGE</title>
'. include $_SERVER['DOCUMENT_ROOT'] . '/../../path/to/include/datepicker.php'.'
</head>
<body>
<p>CONTENT</p>
</body>
</html>
';
echo $pageStart;
exit;
?>
And - datepicker.php:
<script language="Javascript">
var datefield=document.createElement("input")
datefield.setAttribute("type", "date")
if (datefield.type!="date"){ //if browser doesn't support input type="date", load files for jQuery UI Date Picker
document.write('<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />\n')
document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"><\/script>\n')
document.write('<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"><\/script>\n')
}
</script>
<script language="Javascript">
if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget:
jQuery(function($){ //on document.ready
$('#birthday').datepicker();
})
}
</script>
Now there are no syntax errors in either page, great... So I try it, half expecting things to finally just work...
Nope... Fatal Error: failed to open stream: No such file or directory blah blah. This error relates to the include that i added. So okay, even though the file is there, it is not being validated as php because there are no opening and closing php tags.
So I add them... Annnd... A page full of syntax errors again!
So my question is this:
Could some please share some knowledge and explain to me roughly how this process actually works. Whats the deal with all the syntax errors, and how are you supposed to go about a task like this?
I believe it is possible, and yes it would ceratinly be easier if i was not outputting the entire html via php. But this is a simple example and my actual design is alot more complex. It requires for the different parts of the page to be broken up into variables, in order to place those bits and peices when needed, dynamically.
Any input, suggestions, or insight would be greatly appreciated; and any links to pages or tutorials that cover this would also be greatly appreciated.
Thank You!!
All you need to do to use jQuery with PHP is to include the jQuery javascript file in your HTML document in the head tag. I actually use PHP along with jQuery all the time. And this is how I do it. In your code above, it looks like you have some escaping issues with your code. And it also looks like you want to hold the header of the page in a PHP variable then print it out. You don't have to do all that. Just put the plain text in your PHP file without any php tags and it will work. Also, you are using an old version of jQuery. Should probably use the latest version. But, if you need it stored in a PHP variable so that you can print it out, do this:
SO, here is some code to get you started.
<?php
$pageStart = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MY WEBSITE PAGE</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$("#date").datepicker();
});
</script>
</head>
<body>
<input type="text" id="date" name="date" />
</body>
</html>';
print $pageStart;
?>
<head>
<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// javascript & jquery code
// even better would be if you would put client code in separate file!!!
});
</script>
</head>
<body>
<?php
echo "bla bla bla";
?>
</body>
and +1111 to # Heera's comment
You're missing the basics's.
Use Heredoc. Thousands of syntax errors will be gone.
See the heredoc version of your pages,
http://pastie.org/3412925
http://pastie.org/3412929
http://pastie.org/3412935 // Here you have used include to contact. include does not return anything. It just includes. So Its changed differently.
I think it should be
. (include ($_SERVER['DOCUMENT_ROOT'] . '/../../path/to/include/datepicker.php')) .
otherwise php will try to include all the stuff after until the l is reached (tags will be interpreted as part of the file name).
also, in terms of the php code, after the file is included (on success), the include statement translates into 1 as a number, instead of the content of the file.
use
<? $abc <<<qwerty
...
...
...
qwerty;
return qwerty;
?>
for all the files that you want to include

Categories