Missing form when including a php file - php

Why is that when i comment this code my form shows then,
After removing the double backslash from the include("c.php"); ,the form disappears
Here is the content of c.php

try include files always on the top above <body> of the page

Check if c.php doesn't provoke any fatal error. That would end the whole script, hence the form not showing anymore.
By removing error_reporting(0) you would also be capable of seeing that error ;-)

Related

What gets executed first? Is it script inside php tag or HTML?

I have a file with .php extension.
I am following a tutorial and it has both and in a same file.
So the file looks something like:
<?php
?>
<!DOCTYPE html>
<html>
</html>
I was wondering which gets executed first?
BTW, this is a sidetrack to this problem.
This particular file has to do with preventing CSRF attack.
Inside HTML, there is a PHP snippet that looks like
<?php Token::generate() ?>
in one of the hidden text fields.
I am not sure why he put both front end and back end in one file.
Is this the necessity to do CSRF prevention?
Thanks in advance.
PHP gets executed on the server, output of this execution is a HTML code.
The browser takes the HTML code and displays it.
I think the execution is based on the order written in the file. Since PHP is on the top, PHP gets executed first.

Can't locate output affecting HTML and file output

Below are screenshots of the output within Chrome dev tools, and one of my controller methods.
The second screenshot is of an empty controller that simply die();'s.
The third is the controller that is outputting the second image.
I've trawled all files in my app in an attempt to locate the cause of the erroneous output, with no success.
It appears to be an accidentally commented <?php tag, but I can't see how that would cause the doctype error?
I should note that this is happening globally, and I've already checked my existing doctype declaration and opening php tags.
At my wit's end, thanks for any help.
It turns out the extra output was caused by an empty Helper file, that only contained <?php and nothing else.
This appears to have resulted in the <?php not being parsed as PHP, and output as text in an HTML comment somewhere down the line.
try to remove the comment
and i you want use php comment it should be inside php tags
<?php /* comment */ ?>
and if you want use html comment it should be inside html tags
<html>
<!--comment -->
</html>

How do I get rid of white spaces at the top of my webpage?

I am developing a website in PHP and one thing is annoying me a lot. There is a lot of white space before beginning of the webpage at <!DOCTYPE html>.
Have a look at the screenshot of source code of my webpage and google's home page :
This is really annoying. I don't know what makes those lines jump down to line-6 when it should be at line-1.
The source code of my webpage is -
<?php
header('Content-Type: text/html');
require_once 'core.php';
$index=new Index();
$index->run('home', array('file.js', 'script.js', 'main.js'), array('style.css'));
?>
<!DOCTYPE html>
<!-- rest of the DOM here -->
I think there must be some echo thing in core.php that is printing some white space but it is not so. There no echoing before <!DOCTYPE html>.
What is happening? Please help me out.
Remember, there's no such thing as a "php script". There's only files which have PHP code blocks embedded in them. The following file would output 4 blank lines, even though there's absolutely no "echo"/"print" calls in it:
<?php
// this is just a useless comment
?>
<?php
/// and another useless comment, 4 lines later
?>
ANY text outside of a <?php ?> bracket pair is considered output by the PHP engine.
Does core.php (or any of the files it includes) have blank lines after the final ?>?
If so, delete the ?>. It's best to let the final ?> be implied by the end of the file.
Otherwise, just start bisecting your codebase until you can determine what is adding it.
There's a good chance this is being caused by white space at the end of PHP files that are being included (assuming 'core.php' includes a number of other files). The simplest way around this (and best practice generally), is to omit the final ?> at the end of PHP files. It is optional anyway.
Another quick thing you could try to diagnose this would be to move your (unnecessary) header() call down a line so it is below the core.php include. If this script is causing browser output you'll then get the standard PHP 'headers sent' error, which will tell you where output started.

Php Include function causes whitespace and ignores style

I have a page that uses another page via the include() function. The page that requests and uses this external page has some html embeded as well as some output using the echo function. Here is an example of what I am referring to.
page Apple.php contains:
<html>
<head></head>
<body>
<h1>I have some content here.</h1>
<div id="format" style=" width:20px; height:20px;"><?php include("Orange.php") ?></div>
<h2>Some more content here.</h2>
</body>
<html>
page Orange.php contains:
<?php
$astringA='blue';
$astringB='berry';
include("someExternalPage.php");
echo "fruit is ".$astringA.$astringB.$externalVariable;
?>
Whenever the Apple.php is viewed in browser, only the top part of its body is shown(the part above the include function) and everything below the div box is lost and filled with whitespace. In addition the included file ignores all style that the div box has. The same is true for the Orange.php; all output below the include() function is lost. How can I fix this so that the included file will conform to the style I want for it and also to continue to output the rest of the content on the pages?
I also notice that even if I try outputing the rest of the page through php such as
echo ">h2>Some more content here."; (I deliberately inverted the first ">" in the line above so that I illustrate the code here)
the included still takes precedence over the current page and thus the output is never shown.
Smells like you have a hidden fatal error here.
Try using error_reporting(E_ALL) and run the page to see if you have an error...
There's something wrong either with someExternalPage.php or $externalVariable.
If someExternalPage.php is actually an external file (ie you are including a file such as http://example.com/test.php) you may need to check that you have enabled allow_url_include in your php.ini
Alternatively, please make sure someExternalPage.php exists.
Looks like you're missing a semicolon after the include in Apple.php. Can we see the output when you try to load Orange.php? It's helpful to see exactly where the flow is breaking.

Remove blank line on every web page

I have 3 blank lines at the beginning of every page that is causing errors of an add-on with stamps.com. (PS I have worked closely with their support team).
I can see the lines using firebug, but don't know which file is causing them.
I am trying to REMOVE these lines but can't seem to locate them in the header and main_page php files, for templates, common and default folders.
I am using version 1.3.8a of Zen Cart.
The web site is pranajewelry.com
Any suggestions on which files in order of precedence and what special code I should look for?
Ensure all output buffering is of.
Call headers_sent($file,$line); at a point in time you know you already sent output (doesn't matter where, it can be at the end of the request).
VoilĂ , $file & $line hold the position where output started.
If the return of headers_sent is true, but $line==0, you'll have to look into auto_prepends.
I am surprised that those 3 blank lines cause problems with anything.
Anyway, they could be just about anywhere. Look for any lines in your files that aren't within PHP tags. You could have a common include for example that has 3 blank lines at the end of it. It could be anything. Typically, it will be before or after your <?php ?> blocks.
I'd say those lines would have to be in one of your first includes in your template. Quite possibly you may have whitespace outside of you <?php ?> blocks for your configuration or function include files.
hey if you want to remove blank line then replace that web page/s with "notepad++ software".
it has advance text processing capability. or remove it with "macromedia dreamweaver 8.0"
it has tag replacing options with you can replace blank lines present in all pages in website folder.
Locate this in your files in the directory (use search in files) and you will probably find the blank lines
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
Make sure to look after your closing ?> as well. Anything after it will be sent to output; this is actually a good reason why you shouldn't use the closing ?> at the end of your PHP files.
if you are using Dreamweaver try this out
Open the file
Click CTRL + F
Select "Current document" in "Find in" (You can also select the folder if you have multiple files)
Search in "Source code"
Tick "Use regular expression"
Type "[\r\n]{2,}"(without quotes) in "Find"
Type "\n" (without quotes) in "Replace"
Press "Replace All

Categories