I have some problems when I include a PHP file. I am trying this for the first time so I don't really know how to get this is working. The PHP file doesn't respond anymore when I include something. Here is some code:
<html>
<head>
<title>Testing opus class</title>
</head>
<body>
<?php
include('eedce5ed141dd72b552b7abdeb48ede3ddebc0c4.php');
$opus = new opus();
print "Test"; // It isn't printing "Test" over here
Check if you get any errors with error reporting:
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
?>
Also make sure you don't have any error's in the file which you include!
Related
In firefox I repeatedly tried to get PHP working, but no luck
My code is as follows:
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
I used PHP format, but it wanted to save the script again.
XML threw a boatload of errors.
HTML did not show the PHP
<html>
<head>
<title>Location redirect test page</title>
</head>
<body>
<?php
header('Location: http://www.google.com');
?>
</body>
</html>
I uploaded this code to my server(1 and 1). Its not redirecting. I used the same code in XAMPP and it worked fine.
What am I doing wrong? Why is it working on xampp and not on real (1and1) server? I appreciate any help.
Thank you
You can not call header function after output. it shows warning as "header already sent...".
you must write it before tag.
<?php
header('Location: http://www.google.com');
?>
<html>
<head>
<title>Location redirect test page</title>
</head>
<body>
</body>
</html>
*may be your server setting for showing warning is off so it wont display warnings to you on related server.
If by some reason you can't place the php snippet before the html code (like Mayur said) you can use JavaScript for redirects
window.location.href = "http://stackoverflow.com";
Remember that when setting headers from php or setting cookies no text must be out putted before the php command!
I am not an expert but I am no noob at PHP, yet for whatever reason I am stomped as to why my document will not load. Here is my code.
<?php include 'header.php'; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<body>
<p>Hello everyone</p>
</body>
</html>
When I pull out the PHP portion the HTML loads fine. Here is the code in my header.php file.
<?php
<href="index.php">Home</a>
?>
I have tried this on two different hosts, both of which are hosting other PHP websites and still getting issues. I have also validated it with W3Schools and another online PHP validator. Both didn't find any errors. Any help would be greatly appreciated.
Enable errors to see errors, this way:
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);
This code is a PHP error:
<?php
<href="index.php">Home</a>
?>
Try change to:
<?php
echo '<href="index.php">Home</a>';
?>
This:
<?php
<href="index.php">Home</a>
?>
Is no valid PHP. This would, however work:
Home
Inside of the PHP-tags you can only use PHP - no HTML. Also, <href> is no HTML tag.
Look at this question How to get useful error messages in PHP? to find out, how to enable error messages in PHP.
I am including a php file into JQuery, like this:
Main php file:
<?php
session_start();
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<?php
$_SESSION['ID'] = "32";
?>
<div id="sesion"></div>
<script>
$("#sesion").load("fun.php");
</script>
php file that will load, fun.php:
<?php
session_start();
echo 'new php';
echo $_SESSION['ID'];
?>
fun.php shows blank as soon as I add session_start() if i remove it, it will display:"new php"
I need to open session in the "fun.php" file, but I can't seem to achieve it.
Put session_start() at the top of the page that is including chalk_element.php within it's page
Try simplifying your environment.
Create a new index.php with session_start() at the very top, then create a couple of session vars.
Next, create your chalk_element.php file and load it via jQuery in index.php.
Now do something very simple to access a session var and see what happens. This will give you a simplified test environment where you can experiment with the configuration.
It sounds like your outputting something (HTML) before the point you call session_start. You can either move session_start() so it's at the top of the page (right at the top, no whitespace) or call ob_start() first. You can then output data and call session_start() later.
Also, check your error logs for any useful error information as to why the PHP file has just stopped working.
Both files will require session_start(); at the top of each file before any other output as this function sends out several HTTP headers.
Here is a simple example:
index.php
<?php
//Start session
session_start();
//Set the value in your session
$_SESSION['key']='value';
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<script>
$(function() {
$("#Chalk").load('chalk_element.php');
});
</script>
<div id="Chalk">Loading...</div>
</body>
</html>
chalk_element.php
<?php
//Start session also to `resume` session
session_start();
//Check from ajax
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'){
//output session var if set
echo isset($_SESSION['key']) ? $_SESSION['key'].' was set in session' : 'session value was not set';
}
?>
It was an encode problem when I saved the files. I saved both files in ANSI code and problem solved.
Try This One..!
ob_start(); //top of the page
ob_flush();//end of the page
When I create file index.php in directory /public/ my source code
<html>
<meta name="ROBOTS" content="NOARCHIVE">
<head><NOFOLLOW><noindex>
<?php echo '123' ?>
</NOINDEX></NOFOLLOW>
</head>
<body>
</body>
</html>
from browser looks like
<html>
<meta name="ROBOTS" content="NOARCHIVE">
<head><NOFOLLOW><noindex>
123
</NOINDEX></NOFOLLOW>
</head>
<body>
</body>
</html>
but if I create folder (no matter where) and place file index.php into it when source code become
<html>
<meta name="ROBOTS" content="NOARCHIVE">
<head><NOFOLLOW><noindex>
if I make some correction in this file, source code stay the same, not changed in browser view.
Why I cant create and run php code where I want, except /public/ folder?
Is that the exact code you are using in both index.php files?
If so, they should both fail as there is a syntax error. You are missing the ; at the end of the php code.
You posted: <?php echo '123' ?>
Should be : <?php echo '123'; ?>
If that´s not the case, you could add the following to the top of index.php to make sure the errors are showing on the page:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
If any error appear after that, please post them back here.