install reCaptcha and white page - php

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.

Related

In php when copying a file it doesn't show the content in the browser

I have this code in the file register.php
copy("template.php", "username.php");
And then I have the file welcome.php which should make link to username.php. For any new registered user I should create a special page, like username1.php, username2.php, and all this links appear on welcome.php, so that every user should click on their own pages.
The file template.php works fine, it is executed in browser, but the new file shows a blank page in browser. What's the reason ? What should I do ?
If the file template.php would contain only html code, it would work fine, i tried it, but I need to put also php code in the file template.php, in which case the file username.php doesn't work, that's the problem.
The template.php contains
<?php
session_start(); // and also some decisions about session
?>
<html>
<body>
// some text
</body>
</html>
SOLVED
I have used
require("credentials.php");
and this file wasn't found (was only in the root), that's why the page stopped.
Since I cant comment yet.
I think you need to check the content of the template.php.
I tested the copy function and it worked.
here is the code i tested
ori.php
<?php
echo 'hi there';
?>
index.php
<?php
copy('ori.php', 'copy.php');
?>

Code any where returns commented PHPcode

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

the webserver stop displaying my php file after first php end tag

I have a strange problem .... I made an php (some_name.php) file combined with some html and uploaded that file to my webserver.
The file has the code inside structured like this:
<html>
<head>
some html code
</head>
<body>
some more html code
<?php
some php code
?>
some more html code
<?php
some more php code
?>
again some more html code
................
</body>
</html>
When I try to view the file/page in my browser ..the page is not displayed after the first block of php code (no errors ..page works well on my localserver) ..so basically I see just the firs part of the page ..not any html code or php code after the first block of php code ends ( first "?>").
Anyone can help me with this? How can I see the full page, why it not execute the rest of the code?
I put this piece of code
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<html>
<head>
some html code
</head>
<body>
..........................
at the beginning of the file and still no errors are showing ... and still I see just a part of the page.
It is most likely some reference that is different between the localhost and webserver, and you will probably need the error to pinpoint it. If you don't have access to/ can't find the php error log, You can temporarily display errors by adding
ini_set ('display errors', 1);
error_reporting (E_ALL);
To the top of the page. If you throw up some code it might be obvious enough to pick out the issue.
**sorry about the formatting, I can't seem to get the mobile editor to cooperate.

PHP MAMP not showing all of HTML document

I am using MAMP. None of my code after the PHP tags displays in a browser.
I suspect it's something related to what content I can send to the browser after sending PHP? Or what content can be sent before the HTML doc?
Code:
<?php
/* Web Controller for searching music */
session_start();
echo "I display fine!";
?>
<html>
<head>
<title>Listen2me</title>
</head>
<body>
<h1>Listen2.me</h1>
<input type="text" name="songChoice" value="Search songs">
</body>
</html>
Maybe the missing doctype declaration could affect the display:
<!DOCTYPE html>
Did you try uploading the file to a different server to see if it's a problem with your localhost or a problem with your file?
When I run into issues where the code looks fine but it's not working fine, I always run it through BBEdit's "zap gremlins" feature. You might have an invisible bad character in there somewhere that's messing stuff up. If you don't have BBEdit, you can recreate the document from scratch. Don't copy-paste, because you'd just be copy-pasting any bad characters right back into the new document.

_SESSION['xxx'] not being retained across pages in my web application

I have an html file which has inline php. The index.html looks roughly as follows
<?php session_start(); echo $_SESSION['xxx']; ?>
<form action=blah.php> ... </form>
And in blah.php, I do a
$_SESSION['xxx'] = "foo";
header('Location: index.html');
However, when index.html is shown for the second time, I do not see the "foo" message.
Then check your server settings. Try to set send session values in address line (like GET request).
Run this bit of code before your starting your session. It's possible there is an error accessing the session file
ini_set("display_errors", "stdout"); error_reporting(E_ALL);
PHP cannot parsed by HTML files, I mean PHP codes cannot run by HTML, you can try like
<!--#include FILE="test.inc" -->
Above code is HTML file include and put your PHP codes in .inc file, but you have to make some changes in Apache

Categories