Code any where returns commented PHPcode - php

When I put some PHP code in index.php, my PHP code does not show up in my browser (I use firefox). In Firefox's dev tool the PHP code
<?php include 'header.php'; ?>
becomes
<!--?php include 'header.php'; ?-->
It is on Codeanywhere, HTML container on Ubuntu

Just try to see the tutorial first. http://docs.codeanywhere.com/quicktutorial.html

Related

How to stop PHP echoing a "1" after being called from "include" within a HTML file?

I'm trying to call my navigation bar by using the following within my HTML code:
<?= include 'subfolder/topbar.php'; ?>
However, because the script is successfully running, it's echoing a "1" on completion, before my page continues rendering more HTML.
This is then screwing up the spacing within my page.
I've tried to read up on this (and looked at similar threads) but can't find a working resolution.
How do I include the contents of the PHP file without it echoing "1" on completion?
I've also tried putting the include in a variable, but it still outputs the "1":
$myX = (include 'subfolder/topbar.php');
I've also tried using:
include 'subfolder/topbar.php';
return ob_get_clean();
But this just halts the output altogether (so the rest of the page doesn't render), much like using the "exit" command.
The correct way should be
<? include 'subfolder/topbar.php'; ?>
or
<?php include 'subfolder/topbar.php'; ?>
Your code
<?= include 'subfolder/topbar.php'; ?>
is like saying
<? echo include 'subfolder/topbar.php'; ?>

PHP require_once not working for footer

I want to add a common code for footer on all my web pages. I created a new php file named commonFooter.php and have the below code in it:
<?php
echo '--footer-code-in-html--';
?>
On my home page I added the below code:
<?php require_once('/static/v3/commonFooter.php'); ?> // /static/v3 is the path of the commonFooter.php
But somehow the footer is not showing up on the webpage. Can anyone help me out what am I missing.
The require_once statement is identical to require except PHP will check if the file has already been included, and if so, not include (require) it again.
See the include_once documentation http://php.net/manual/en/function.include-once.php
Try
<?php echo('/static/v3/commonFooter.php'); ?>
If that works and the statement is printed out in the page , Try
<?php require_once('static/v3/commonFooter.php'); ?>
If that fails, then take a share the folder structure of your project.

php - include_once seems to print the desired page into the html

My problem is that I try to include a class using include_once(); but instead of including the desired file, it prints the code in the file straight into the source html so the code appears on my webpage.
This is the code:
<?
include_once('php/class.loadClients.php');
$client = new loadClient();
$client->connect();
?>
I'm not sure why its doing this as I've used include_once(); elsewhere in this page and it works fine:
include_once('php/class.register.php');
Thanks in advance!
Open php/class.loadClients.php, and add <? to the beginning of it.
To add to Paulpro's answer: if his solution does not work your server might not have short tags enabled ( <? vs <?php ). Use the full <?php tag.

php include breaking

I have a php page that generates all the html and echo's it. Now I want to write a php script that I can use include to handle the footer code. that way if I need to update the footer on all the pages I can just edit the code in the included page.
But when I use include("footer.php"); and the footer page contains the footer code that works if it exists on the page it breaks and prints the code. Im very confused as too why?
if(isset($_SESSION['user_cart']) && count($_SESSION['user_cart']) > 0)
Starts writing the code on the page if I include from 0)
Please help?
EDIT: The code in the footer is wrapped in <?php ?>
You need to wrap that code in footer.php with php tags.
<?php
if(isset($_SESSION['user_cart']) && count($_SESSION['user_cart']) > 0) ...
?>
Dont your short hand notation of php tags <? ?>, use <?php ?>instead...
It sound like you didn't start php file with
<?php
Please make sure that your footer file has <?php in the beginning.
I'm not sure if you stated your question very clearly.
If you are echoing code out it will appear as soon as you include the file. Your file should look like this:
<?php require_once 'header.php';
// content goes here
require_once 'footer.php'; ?>

install reCaptcha and white page

I've downloaded librecaptcha.php and made test.php:
<?php
require_once('recaptchalib.php');
$publickey = "MY_KEY"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
But it shows white screen. Problem is in require_once(), because if I exit with echo before require_once() - it echoes to page, but if after require - doesn't echo.
File recaptchalib.php is in the same folder as the test.php
What it can be?
UPD 1:
I think, the problem is in require_once('recaptchalib.php'). No matter what code is after it, white screen will apear.
For example:
<?php
require_once('recaptchalib.php');
exit('test_after');
?>
This file return white screen. But this script works:
<?php
exit('test_before');
require_once('recaptchalib.php');
?>
So, the problem is in lib file itself. Path is correct, and I haven't modified the file.
UPD2:
So, I should to check recaptchalib.php file.
I've create lib.php file with such content:
<?php
echo "lib";
?>
It've been opened in all browsers. But then I've added (copy-pasted) the content of recaptchalib.php before echo "lib". So it looks like:
<?php
/* recaptchalib.php content*/
echo "lib";
?>
And I've seen blank screen in FF, 500 server internal error in Chrome and Remove server or file not found on Opera.
UPD3:
recaptchalib.php began to work only when I've copied it's content function-by-function in a new file. (when I copied whole content - it hasn't work). I don't understand why??
No it's not problem in library!
Your test script will work in Safari but will not work in Firefox! (I don't know for rest of them because I use just these)
Have you tried to check it in more than one browser?
According to official documentation: Using reCAPTCHA with PHP you have to put PHP code on HTML page.
The body tag is required or the
CAPTCHA may not show on some browsers
So you have to create HTML page and it will work
<html>
<body>
<!-- your HTML content -->
<form method="post" action="submit_recaptcha.php">
<?php
require_once('recaptchalib.php');
$publickey = "your_public_key"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
<input type="submit" />
</form>
<!-- more of your HTML content -->
</body>
</html>
Here's my test (works in all browsers)!
Here's your code on my server (it doesn't work in FF, but works in Safari)
Update:
Also double check is your domain on reCaptcha page same as one where you use your code.
Example:
This is exact copy of my working example from server (removed Public Key)! This is what I have here http://service-kl.com/code/recaptcha/
Give it a try, but before that, you have to replace public key in index.php with your own.

Categories