I have recently setup a Fedora 20 VPS with LAMP. My PHP is working properly as you can see from output below:
http://talkoot.co.in/info.php
My problem is when I access page below, the php script is printed out instead of being executed. If one 'Views Source' then the entire code is visible.
http://talkoot.co.in/WebBackend/admin/login.php
Can someone help me out. Here is the code for login.php:
<?php
include 'init.php';
if(isset($_SESSION['admin'])){
header('Location: index.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>Login - CPanel</title>
<link type="text/css" rel="stylesheet" href="libs/css/materialize.min.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="libs/css/style.css" media="screen,projection"/>
</head>
<body>
<div class="container">
<div class="card publish-form-container">
<?php
if(isset($_POST['username'],$_POST['password'])){
$__USERS->adminLogin($_POST);
}
?>
<form class="col s12" method="POST" action="" >
<div class="input-field">
<input id="username-field" type="text" name="username">
<label for="username-field">Username...</label>
</div>
<div class="input-field">
<input id="password-field" type="password" name="password">
<label for="password-field">Password...</label>
</div>
<div>
<button class="btn waves-effect waves-light pull-right" type="submit">Login
<i class="mdi-content-send right"></i>
</button>
</div>
</form>
</div><!-- Post Card //-->
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="libs/js/materialize.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.materialboxed').materialbox();
});
</script>
</body>
</html>
Your server is not enabled for Short Open Tag there are 2 scenarios
enable it from php.ini short_open_tag = On or using htaccess
Use <?php instead of <?
P.S: i have shared a link which can explain you why i presented 2 options
As I can see in your phpinfo page:
short_open_tag Off Off
that means the short open tag are now allowed
So, anything you put inside short tags <? ?> won't be parsed as PHP. You'd rather put it inside standard tags <?php ?> block.
Related
I am trying to generate a QR code from the value of a HTML input element:
HTML, CSS, and JS Code:
index.php
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="icon" href="https://codingbirdsonline.com/wp-content/uploads/2019/12/cropped-coding-birds-favicon-2-1-192x192.png" type="image/x-icon">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js" integrity="sha384-LtrjvnR4Twt/qOuYxE721u19sVFLVSA4hf/rRt6PrZTmiPltdZcI7q7PXQBYTKyf" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<title>Send Email Example</title>
<style>
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-9 col-md-7 col-lg-5 mx-auto">
<div class="card card-signin my-5">
<div class="card-body">
<h5 class="card-title text-center">Generate QR Code</h5>
<form id="generateQrForm" class="form-signin">
<div class="form-label-group">
<label for="inputEmail">Text For QR <span style="color: #FF0000">*</span></label>
<input type="text" name="qrText" id="qrText" class="form-control" required placeholder="Enter something to generate QR">
</div> <br/>
<div id="generatedQr text-center">
<img src="" id="generatedQrImg" class="center-block">
</div> <br/>
<button type="submit" name="generateQrBtn" id="generateQrBtn" class="btn btn-lg btn-primary btn-block text-uppercase" >Generate QR</button>
</form>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="generate_qr_js.js"></script>
</script>
</body>
jQuery code:
generate_qr_js.js
$("form#generateQrForm").on("submit",function (e) {
e.preventDefault();
var qrText = $("#qrText").val();
$.post("generate_qr_script.php",{generateQr:'generateQr',qrText:qrText},function (response) {
var data = response.split('^');
var generateQrImgPath = data[1];
$("#generatedQrImg").attr("src",generateQrImgPath);
})
});
PHP Code:
generate_qr_script.php
<?php
include "library/phpqrcode/qrlib.php";
if (isset($_POST['generateQr']) == 'generateQr')
{
$qrText = $_POST['qrText']; // receive the text for QR
$directory = "generated_qr/"; // folder where to store QR
$fileName = 'QR'.rand().'.png'; // generate random name of QR image
QRcode::png($qrText, $directory.$fileName, 'L', 4, 2); // library function to generate QR
echo "success^".$directory.$fileName; // returns the qr-image path
}
?>
I run these 3 codes under one folder along with phpqrcode library that is imported in generate_qr_script.php file. When I go to the index.php website using XAMPP server, I get an error saying "404 Not Found" as shown below:
When I inspect the source code, the image source is generated successfully but it doesn't get shown on the web.
What I am trying to do is to generate a QR code that captures what the user inputs into the text box that is written in the HTML code. Ideally, it would be nice to store the barcode into the local computer file within the same folder but the code does not load the desired QR code png.
If anyone has any suggestions on where I am going wrong or has a better idea to generate a barcode please do let me know.
I think I fixed it by changing the file permission where I wanted to save the images somehow!
So all I want is to rotate my webcam using a servo moteur, so when I click one of the three buttons (which the program will execute a python script) I get no result! Please any help?
The Code:
<?php
if (isset($_POST['rotateright'])) {
shell_exec("python Rotateright.py");
}
elseif (isset($_POST['rotatedefault'])) {
shell_exec("python defaultpositon.py");
}
elseif (isset($_POST['rotateleft'])) {
shell_exec("python Rotateright.py");
}
?>
<html lang="fr">
<head>
<meta charset="utf-8">
<link href="camerasurveillance.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container1">
<img class="home" src="home.png"/>
</div>
<div class="container">
<br><br><br>
<!--<img class="live" src="http://192.168.1.8:8082/?action=stream"
width="500" height="350" alt="Live Feed" title="Raspberry pi" />-->
<br>
<form method="POST">
<input class="Rotater" type="submit" name="rotateright" value="Rotation
à droite">
<input class="default" type="submit" name="rotatedefault"
value="Position initiale">
<button class="Rotatel" name="rotateleft">Rotation à gauche</button>
</from>
</div>
</div>
What could be the reason that styles, after ob_end_flush(); are included to the body, instead of the head part?
test.php
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' type='text/css' href='<?php echo SERVER_STYLE_LOG.'etInp.css'; ?>' />
</head>
<body>
<div id='header'>
<h1>
</h1>
</div>
<div id='content'>
<button class="inbk" type="submit" name="redirLogin">Login</button>
<button class="inbk" type="submit" name="redirRegister">Register</button>
<button class="inbk" type="submit" name="redirRemind">Remind</button>
<button class="inbk" type="submit" name="redirContact">Contact</button>
</div>
<div id='footer'>
this is the default footer
</div>
</body>
</html>
If i display test.php on localhost directly, localhost/folder/folder/test.php - i am geting the right styles (buttons are aligned horizontally), and if i check, they are included in the head part.
If i display test.php using simple mvc, i get wrong styles (buttons are vertical), and the stylesheet and metatags are included in the body
ob_start();
$viewData = $this->data;
include_once( $this->viewTemplPath.$this->file );
ob_end_flush();
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 7 years ago.
I have programmed a web application, which requires you to login first, before having access to the actual content of the application.
I am setting the value 'logedIn' to false when a user enters the homepage like this:
<?php
$_SESSION['logedIn'] = "false";
?>
If the user tries to go to overview.php, the code checks if the value of logedIn equals 'true'. If it is not, a header relocates the window to the login page like this:
<?php
session_start();
?>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://jquery-ui.googlecode.com/svn-history/r3982/trunk/ui/i18n/jquery.ui.datepicker-nl.js"></script>
<script src="../javascript/overview.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/mainpage.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
</head>
<body>
<?php
if($_SESSION['logedIn'] != "true") {
header("Location: ../index.php");
exit();
}
?>
<div class="container-fluid z-container">
<div class="row z-overview-top-menu">
<div class="col-md-2 z-background-dark z-top-nav z-border-right" id="menu_logo">
<h3>Logo</h3>
</div>
<div class="col-md-2 z-top-nav z-item-hover z-border-right z-selected" id="menu_diary" onclick="changeMenu('diary')">
<h3>Dagboek</h3>
</div>
<div class="col-md-2 z-top-nav z-item-hover z-border-right" id="menu_pazo" onclick="changeMenu('pazo')">
<h3>Pazo</h3>
</div>
<div class="col-md-2 z-top-nav z-item-hover z-border-right" id="menu_counter" onclick="changeMenu('counter')">
<h3>Tellers</h3>
</div>
<div class="col-md-2 z-top-nav z-item-hover z-border-right" id="menu_overview" onclick="changeMenu('overview')">
<h3>Overzicht</h3>
</div>
<div class="col-md-2 z-top-nav z-item-hover" id="menu_comparison" onclick="changeMenu('comparison')">
<h3>Vergelijking</h3>
</div>
</div>
<div class="row">
<div class="col-md-2 z-overview-left-menu">
<ul class="z-left-list" id="userList"></ul>
</div>
<div class="col-md-10 z-overview-main-menu">
<ul id="overviewList" class="z-overview-list-main">
</ul>
</div>
</div>
</div>
</body>
When I replace the header with an echo, I get a response, indicating that the header is indeed executing when I run the code.
Also there are no .htaccess in any of the directories.
Any thoughts on what the problem might be?
http://php.net/manual/en/function.header.php
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
Since you are outputting:
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://jquery-ui.googlecode.com/svn-history/r3982/trunk/ui/i18n/jquery.ui.datepicker-nl.js"></script>
<script src="../javascript/overview.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/mainpage.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
</head>
<body>
before the header call, it will fail.
First of all, let me show you a bit of code:
index.php
<?php echo localize('New directory'); ?>
So, as you can see, I use new-directory-dialog.php as a dialog window. All works fine on local machine, using Wamp server on Win 7 x64. But on my web host server, every dialog page is displayed with ?> (or ?>) chars.
HTML tab in Firebug shows this output:
<html class="ui-mobile">
<head>
<base href="http://pantljika-online.info/link/new-directory-dialog.php">
</head>
<body class="ui-mobile-viewport ui-overlay-a">
?>
<title>Novi direktorij</title>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
I have no clue why is this happening.
Here is entire code for dialog page:
<?php
include('localize.php');
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo localize('New directory'); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<div data-role="page" data-theme="<?php echo $_SESSION['data-theme']; ?>" >
<form action="index.php" method="post">
<fieldset>
<div data-role="header">
<h1><?php echo localize('New directory'); ?></h1>
</div>
<div data-role="content">
<label for="new-directory-name">
<?php echo localize('Name'); ?>:
</label>
<input type="text" id="new-directory-name" name="new-directory-name" />
</div>
<div data-role="footer">
<h4>
<button type="submit" name="submit" value="submit-value"><?php echo localize('Create'); ?></button>
</h4>
</div>
</fieldset>
</form>
</div>
</body>
</html>
OK, problem solved. I deleted PHP closing tag (?>) in one of the included php files and it stopped showing up on dialogs. Also I had to encode all php files from UTF8 to UTF8 without BOM. Otherwise jQuery puts head metatags and title tag inside body element...