I have the Following test document:
<!DOCTYPE html>
<html>
<head>
<title>A Word finding Tutorial
</title>
</head>
<body>
<?php
include "inc/header.php";
?>
<form action="test3.php" method="GET">
Text Field: <br> <textarea name="long_text" rows="4" cols="50">Enter the Para Here.</textarea>
<br>
Finding : <br> <input type="text" name="find" value="Enter the word to find">
<input type="submit" value="Submit">
Result:
</body>
</html>
Now the header.php file is Somewhat like This:-
<html>
<head>
<style>
img#imgheader {margin:5px;padding:10px 5px;}
div#header {background-color:#ccff33;}
</style>
</head>
<body>
<div id="header" style="text-align: center;">
<img id="imgheader" src="\test\img\trial.png" alt="header" height="30px" width="60px">
</div>
</body>
</html>
Now My Problem is that it is basically messed up when it is Being outputed like I saw the Source code Of final Output of test.php is as Follows:-
<!DOCTYPE html>
<html>
<head>
<title>A Word finding Tutorial
</title>
</head>
<body>
<html>
<head>
<style>
img#imgheader {margin:5px;padding:10px 5px;}
div#header {background-color:#ccff33;}
</style>
</head>
<body>
<div id="header" style="text-align: center;">
<img id="imgheader" src="\test\img\trial.png" alt="header" height="30px" width="60px">
</div>
</body>
</html>
<form action="test3.php" method="GET">
Text Field: <br> <textarea name="long_text" rows="4" cols="50">Enter the Para Here.</textarea>
<br>
Finding : <br> <input type="text" name="find" value="Enter the word to find">
<input type="submit" value="Submit">
Result:
</body>
</html>
As You could see the final output has like an Html page inside an HTML page. So basically it does not optimized by w3 but it can produce errors in future.
My question is is it right way to do so or not and if not how to write it so it does not get messed up finally.
It seems pretty clear that your included file should not contain those headers. I suggest you first create a css file
mystyle.css
#header {text-align: center;}
img#imgheader {margin:5px;padding:10px 5px;}
div#header {background-color:#ccff33;}
Then header.php should look something like (note your slashes will not work),
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<div id="header">
<img id="imgheader" src="/test/img/trial.png" alt="header" height="30" width="60">
</div>
It currently includes the duplicated html tags because you included them in header.php.
This is not correct HTML. You must edit your header.php file to:
<?php
function returnHead() { ?>
<style>
img#imgheader {margin:5px;padding:10px 5px;}
div#header {background-color:#ccff33;}
</style>
<?php }
function returnBody() { ?>
<div id="header" style="text-align: center;">
<img id="imgheader" src="\test\img\trial.png" alt="header" height="30px" width="60px">
</div>
<?php }
?>
And then turn your test document to:
<?php
include "inc/header.php";
?>
<!DOCTYPE html>
<html>
<head>
<title>A Word finding Tutorial</title>
<?php returnHead(); ?>
</head>
<body>
<?php returnBody(); ?>
<form action="test3.php" method="GET">
Text Field: <br> <textarea name="long_text" rows="4" cols="50">Enter the Para Here.</textarea>
<br>
Finding : <br> <input type="text" name="find" value="Enter the word to find">
<input type="submit" value="Submit">
Result:
</body>
</html>
Related
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>
I have a webpage and a place to submit data. I made a preview page for this, and whenever a user clicks 'preview' he can see what it would look like. The trouble is whenever they click the back button from the preview all the data is gone. How do I avoid this and keep the data without any very complex solutions?
preview.php
<?php
session_start();
$getTitle = $_POST['title'];
$getEntry = $_POST['entry'];
date_default_timezone_set('UTC');
$getTime = date('D, M jS, o, H:i a e');
$user = $_SESSION['username'];
?>
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<link rel="stylesheet" type="text/css" href="css/main.css">
<head> <title> Blog - Preview </title> </head>
<body>
<div class="wrap">
<div class="navPreview">
<ul>
<li>Back<br></li>
</ul>
</div>
<div class="main">
<h1>Preview</h1>
<div class="mainscroll">
<?php
echo "<span>Submitted at: $getTime by $user</span><br>";
echo "<h2>$getTitle</h2>";
echo "<p>$getEntry</p><hr>";
?>
</div>
</div>
</div>
<div class="footer">x</div>
</body>
addentry.html
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<link rel="stylesheet" type="text/css" href="css/main.css">
<head> <title> Blog - Add Entry </title> </head>
<body>
<div class="wrap">
<div class="header">
<h2> Welcome.. </h2>
<p>..add an entry below</p>
</div>
<div class="nav">
<ul>
<li>Home<br></li>
<li>Add Entry<br></li>
<li>Logout<br></li>
</ul>
</div>
<div class="main">
<form id="entryForm" action="addentry.php" method="post">
<p class="title">
<label>Title:</label>
<input type="text" name="title"><br>
</p>
<p class="body">
<label>Entry:</label>
<textarea name="entry"></textarea><br>
</p>
<p class = "buttons">
<script type="text/javascript">
function clearConfirm() {
var confirm = window.confirm("Are you sure you want to clear?");
if (confirm) {
document.getElementById("entryForm").reset();
}
}
function previewForm(action) { document.getElementById('entryForm').action = action;
document.getElementById('entryForm').submit();
}
</script>
<input type="button" onclick="clearConfirm()" value="Clear" />
<input type="button" onclick="previewForm('preview.php')" value="Preview" />
<input type="submit" value="Submit" />
</p>
</form>
</div>
<div class="footer">x</div>
</div>
Maybe add a target="_blank" ? It will open the preview in a new tab.
<input type="button" onclick="previewForm('preview.php')" value="Preview" target="_blank"/>
EDIT: Oups not in the form but on your preview link...
Or something like this : http://www.w3schools.com/tags/att_button_formtarget.asp
Hi I am trying to make a personal code playground... I am using Code Mirror to turn into looking like an IDE (I also plan to add features of an IDE later but...). My current code is basically..
HTML (index.html)
<html>
<head>
<link href="main.css" rel="stylesheet" type="text/css" />
<script src="http://codemirror.net/lib/codemirror.js"></script>
<link href="http://codemirror.net/lib/codemirror.css" rel="stylesheet" />
<script src="http://codemirror.net/mode/htmlmixed/htmlmixed.js"></script>
<script src="http://codemirror.net/mode/css/css.js"></script>
<script src="http://codemirror.net/mode/javascript/javascript.js"></script>
</head>
<body>
<div class="codewindow">
<form id="codePush" action="codePush.php" method="POST" target="codeResults">
<textarea id="htmlWindow"></textarea>
<textarea id="cssWindow"></textarea>
<textarea id="jsWindow"></textarea>
<input type="submit" />
</form>
<script class="code">
var htmlCodeMirror = CodeMirror(function(elt) {
htmlWindow.parentNode.replaceChild(elt, htmlWindow);
}, {value: "<!-- HTML goes here -->",
lineNumbers: true,
mode: "text"});
</script>
<script class="code">
var cssCodeMirror = CodeMirror(function(elt) {
cssWindow.parentNode.replaceChild(elt, cssWindow);
}, {value: "/* CSS goes here. */",
lineNumbers: true,
mode: "css"});
</script>
<script class="code">
var jsCodeMirror = CodeMirror(function(elt) {
jsWindow.parentNode.replaceChild(elt, jsWindow);
}, {value: "// JavaScript goes here.",
lineNumbers: true,
mode: "javascript"});
</script>
</div>
<div class="output">
<iframe id="codeResults" name="codeResults" target="codePush.php" width="100%" height="100%" frameBorder="0.5" scrolling="yes"></iframe>
</div>
</body>
PHP (codePush.php)
<!DOCTYPE html>
<html>
<head>
<style>
<?php
echo $_GET['cssWindow'];
?>
</style>
<script type="text/javascript">
<?php
echo $_GET['jsWindow'];
?>
</script>
</head>
<body>
<?php
echo $_GET['htmlWindow'];
?>
</body>
</html>
I have made sure the link to the iFrame works because when adding text to the PHP file in the body section it displays when submit is pressed.
I hope I have made it clear and would appreciate any help...
Just for reference I am a bit of a NOoB when it comes to PHP
I'm not entriely sure what you're trying to achieve with all the code you provided, but here's a simplified version that will fix the main issue of the code not processing in codePush.php:
<div class="codewindow">
<form id="codePush" action="codePush.php" method="POST" target="codeResults">
HTML:<textarea id="htmlWindow" name="htmlWindow"></textarea>
CSS:<textarea id="cssWindow" name="cssWindow"></textarea>
JS:<textarea id="jsWindow" name="jsWindow"></textarea>
<input type="submit" />
</form>
</div>
<div class="output">
<iframe id="codeResults" name="codeResults" target="codePush.php" width="100%" height="100%" frameBorder="0.5" scrolling="yes"></iframe>
</div>
CodePush.php
<!DOCTYPE html>
<html>
<head>
<style>
<?php
echo $_POST['cssWindow'];
?>
</style>
<script type="text/javascript">
<?php
echo $_POST['jsWindow'];
?>
</script>
</head>
<body>
<?php
echo $_POST['htmlWindow'];
?>
</body>
</html>
Note that CodePush.php uses 'POST' not 'GET' so that it is consistent with your form. You were also missing 'name' attributes on the textareas which is what is used in the post (not the ids).
You might want to consider adding in some checks if the fields aren't complete to avoid errors etc.
I would whether someone can help me please.
I have the following test form ('form.html'), which if I use a 'Submit Button' I can pass the 'username' and 'locationid' variables to the next form, in this case 'gallery.php'
<form method="post" action="gallery.php"><br/><br/>
<input type="text" name="username" value="IRHM73" /><br/><br/>
<input type="text" name="locationid" value="1" /><br/><br/>
<input type="submit" name="submit"/><br/><br/>
</form>
and this is the 'gallery.php'
<?php
$_SESSION['username']=$_POST['username'];
$_SESSION['locationid']=$_POST['locationid'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
$galleryPath = 'UploadedFiles/' . $_SESSION['username'] . '/' . $_SESSION['locationid'] . '/';
$thumbnailsPath = $galleryPath . 'Thumbnails/';
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
$descriptions = new DOMDocument('1.0');
$descriptions->load($absGalleryPath . 'files.xml');
?>
<head>
<title>Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="Libraries/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet" type="text/css" />
<link href="Styles/style.css" rel="stylesheet" type="text/css" />
<!--[if IE]>
<link href="Styles/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"></script>
<script src="Libraries/fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() { $('a.fancybox').fancybox(); });
</script>
<style type="text/css">
<!--
.style1 {
font-size: 14px;
margin-right: 110px;
}
.style4 {font-size: 12px}
-->
</style>
</head>
<body style="font-family: Calibri; color: #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: -476px; margin-right: 1px; margin-bottom: -10px;">
<div align="right" class="style1"> <a href = "imagefolders.php" /> View Uploaded Images In Folder Structure <a/> ← View All Uploaded Images </div>
<form id="gallery" class="page">
<div id="container">
<div id="center">
<div class="aB">
<div class="aB-B">
<?php if ('Uploaded files' != $current['title']) :?>
<?php endif;?>
<div class="demo">
<input name="username" type="text" id="username" value="IRHM73" />
<input name="locationid" type="text" id="locationid" value="1" />
<div class="inner">
<div class="container">
<div class="gallery">
<ul class="gallery-image-list">
<?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :
$xmlFile = $descriptions->documentElement->childNodes->item($i);
$name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8');
$description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8');
$folder = htmlentities($xmlFile->getAttribute('folder'), ENT_COMPAT, 'UTF-8');
$source = $galleryPath . rawurlencode($xmlFile->getAttribute('source'));
$thumbnail = $thumbnailsPath . rawurlencode($xmlFile->getAttribute('thumbnail'));
?>
<li class="item">
<a class="fancybox" target="_blank" rel="original" href="<?php echo $source; ?>"><img class="preview"
alt="<?php echo $name; ?>" src="<?php echo $thumbnail; ?>" /></a></li>
<p><span class="style4"><b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br />
<b>Contained in folder:</b> <?php echo htmlentities($xmlFile->getAttribute('folder'));?> </span><br />
<?php endfor; ?>
</li>
</p>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="aB-a"> </div>
</div>
</div>
</div>
</form>
</body>
</html>
I'm now trying to perform the same action but this time via a link rather than a button.
I've not changed my 'gallery.php script, but my revised form is as follows:
<?php
session_start();
$_SESSION['username']="username";
$_SESSION['locationid']="locationid";
echo 'Gallery';
?>
<input type="text" name="username" value="IRHM73" /><br/><br/>
<input type="text" name="locationid" value="1" /><br/><br/>
</form>
However when I load the form I receive the following error:
Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
/homepages/2/d333603417/htdocs/development/form.php:2) in
/homepages/2/d333603417/htdocs/development/form.php on line 3
I'm not too familiar with 'Session variables' as I'm only just learning. But I just wondered whether someone could perhaps take a look at this and let me know where I'm going wrong.
Many thanks and regards
Put the following:
session_start();
at the top of gallery.php, not form.html. Also, You cannot submit a form that way unless you use javascript to submit the form upon click of a link, see here: http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml. Also, you have no opening < form> tag on your form.
session_start() should be called before any output to the browser, so put it before anything is sent. The output is sent from the form.php file.
It seems like somewhere in your php pages you have the session_start(); call after other operations (like print hmtl).
Put always session_start() as the first instruction in php pages
I have a lot going on in my header so I am hoping it is makes some sense. My Header does not render at all. The only part that shows up is the loginfrom2.inc.php I was wondering if anyone can let me know what is wrong
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel=stylesheet type="text/css" href="style.css">
<style type="text/css">
.headerfont {
color: #FFF;
}
</style>
<?php
/*Login Logout*/
if(isset($_SESSION['currentMember'])) {
$currentMember=unserialize($_SESSION['currentMember']);
?>
</head>
<body>
<table width="764" height="97" cellpadding="0" cellspacing="0" border="0">
<tr valign="top">
<td width="248"></td>
<td width="100%" background="img/faddedbanner3.png"> <img src="../img/star3.png" width="94" height="104" alt="Star"> <span class="headerfont" align="center"><strong>The Unofficial Bank of Mike</strong></span></td><td background="../assign4/img/faddedbanner3.png"></td>
<td>
</td>
</tr>
<div id="logout">
<span id="user_session">VALUED CUSTOMER: <strong>
<?=$currentMember->firstname?>
<?=$currentMember->lastname?>
</strong></span>
<a id="logout" href="<?=URL_ROOT?>logout.php" title="logout">LOGOUT</a>
<?php
}else{
require_once('loginform2.inc.php');
}
?>
</table>
</body>
</html>
//////////////////////////////////////////
This is my Loginform2.inc.php You can see the include statement above
<div id="login_form">
<form id="login" method="post" action="processlogin.php">
<p>
<label for="emailaddress">E-Mail Address:</label>
<input type="text" name="emailaddress" id="emailaddress" size="15">
</p>
<p>
<label for="password">Password: </label>
<input type="password" name="password" id="email" size="15">
</p>
<p>
<input type="submit" name="submit" id="login_submit" value="Login"></p>
</form>
</div>
///////////////////////processlogin.php
/*start session*/
session_start();
$_SESSION['currentMember'] = serialize($currentMember);
note the screen shots of my my web page
<?php
/*Login Logout*/
if(isset($_SESSION['currentMember'])) {
$currentMember=unserialize($_SESSION['currentMember']);
?>
Move that block to at least be inside the <body> tag.
When $_SESSION['currentMember'] is not set, the <head> element is never closed.
You also shouldn't be putting anything between the last <tr> and closing </table> tag. Your HTML is a bit of a mess.
Here's how you should probably structure it
<?php session_start() ?>
<!DOCTYPE html>
<html>
<head>
<!-- link / style elements, etc -->
</head>
<body>
<table>
<!-- table contents -->
</table>
<?php if (isset($_SESSION['currentMember'])) :
$currentMember=unserialize($_SESSION['currentMember']); ?>
<div id="logout">
<!-- etc -->
</div>
<?php else : require_once 'loginform2.inc.php'; endif ?>
</body>
</html>
First move that if block inside your body tag, as others have suggested. That means replace this:
<?php
if(isset($_SESSION['currentMember'])) {
$currentMember=unserialize($_SESSION['currentMember']);
?>
</head>
<body>
With this:
</head>
<body>
<?php
if(isset($_SESSION['currentMember'])) {
$currentMember=unserialize($_SESSION['currentMember']);
?>
If that doesn't fix it, take a look at this line:
if(isset($_SESSION['currentMember'])) {
It checks if $_SESSION['currentMember'] has a value other than NULL. If not, loginform2 is displayed instead of your header. I can't see anywhere in the code you've pasted where $_SESSION['currentMember'] is being given a value.
I'm guessing that it should be set in processlogin.php once a user successfully logs in. Perhaps some part of the login process is broken.