I am writing an anti-ddos php script, and I want to write a custom load page, but the html page of the orginal html page would be rendered. Is there anyway for me to prevent the html showing up while showing up my php load page
<?php require "antiddos.php"?>
#Samuel Wang, you can try check that out by one of this examples.
below assume code of antiddos.php and other file from where you include it.
1. antiddos.php :
E.g. before your php code or you can keep html inside the file that won't be an issue.
<?php
echo"<p>This is a test html content of antiddos.php</p>";
function testcall($TextReceiver ){
return $TextReceiver;
}
function MathMultiplication($Prt1,$Prt2){
return $Prt1*$Prt2;
}
?>
2. testprocess.php :
You can use the ob_clean(); function next to your include file statement that will discards the contents / html output from the antiddos.php.
<?php require_once("antiddos.php");ob_clean();
echo testcall("Hello this is print call from testprocess.php to antiddos.php");
echo "<br>";
echo "MathMultiplication= ". MathMultiplication(4,3);
?>
Conclusion by both the files output: First from the antiddos.php and second one from the testprocess.php
Related
For a Wordpress plugin, I made a function that contains a big HTML portion (following WP docs, I used ob_start and ob_get_clean to insert it):
function myShortcode() {
ob_start();?>
<!-- here a lot of HTML -->
<?php
return ob_get_clean();
}
I would like to put the HTML outside this function and include or require it.
Is this possible? Is there something I should be aware of? Is it preferable file_get_contents? Any other tip is appreciated, thanks in advance
You can move your html to separate file and then include it as simple php file after ob_start()... Yes it will work, just make sure your view.php template partial is Echoing that html, i.e. You may have html outside of php tags e.g.
File view.php
<?php //Template code starts ?>
ALL HTML HERE
<?php // Template code ends ?>
And your current function in current plugin php file will become:
function myShortcode() {
ob_start();
include(PLUGIN_DIR_PATH/templates/view.php);
return ob_get_clean();
}
I included an html file like this, so that it is not displayed when the site loads:
<div id="menugrp0" class="menuhide">
<?php include 'menugrp0.html'; ?>
</div>
Now I want it to be shown at a specific spot. I am using this php code, to get some variables which are transported with the $_SESSION. I am using this kind of question for some simple html links, in which case it works perfectly:
if ($_SESSION['gruppe'] == $h['gruppe']) {
printf(' menugrp0.html');
}
I know that this is not working at all at the moment for this included html. I also tried to add the <?php [...] ?> tag inside the printf, which is also not working.
Is it possible to show a hidden included html file with a printf tag?
Try this one.
<?php
if($_SESSION['gruppe'] == $h['gruppe']){
echo 'Foo';
include ('/path/to/menugrp0.html');
echo 'Example: one';
}
?>
readfile('menugrp0.html'); // Reads a file and writes it to the output buffer. It is like read then "echo"
How to echo the whole content of an .html file in php?
Thanks to Daan Meijer, this works.
echo file_get_contents('...');
}
I've just begun learning php and I have created a php page that creates pages dynamically. For example I have used includes for menu.php, header.php and so on.
I would like php to create a html file that contains the rendered php automatically.
My project:
Every time I refresh the index page completely different content loads and I would like to have It automatically create a html version.
If I understand correctly, you want to store the output generated by the PHP script to a file, right? In this case, you could use output buffering:
<?php
// Turn on output buffering
ob_start();
// Create the HTML page content
print '<!DOCTYPE html><html><head><title>test</title></head><body><button type="button">Button</button></body></html>';
// At the end of the PHP script, write the buffered content to a file
$content = ob_get_clean();
file_put_contents('/my/html/pages/page.html', $content);
// Output the HTML to the browser
print $content;
?>
Visit php.net for more info.
I'm learning Php
And i made a main index.php page
And at some point it contains the line
<?php
include './BaseTemplate.php';
?>
BaseTemplate.php contains a lot of common plain html that is equal between all pages.
It looks like (but these are only a few lines) :
echo '<script src = "../assets/js/intention.js"></script>';
echo '<script src = "../assets/js/context.js"></script>';
echo '<head><body>';
echo '<table>';
But these echo commands dont get executed how should i resolve this ?
When you are including any file into your page the code for that file will come into the page.
So if the included file and the page where you are including it are in not in same path will create a problem.
It seems that you are getting that only. So please make the path in BaseTemplate.php according to the index.php, and it will work.
I solved it. I was thinking that include would put all code in a page from an external php source file. That's not the case, include files are libraries with functions which can be called.
So to resolve it, I rewrote it the BaseTemplate.php like this
<?php
Function WritePageBase() { // now i put it all inside a callable function
echo '<script src = "../assets/js/intention.js"></script>';
echo '<script src = "../assets/js/context.js"></script>';
echo '<head><body>';
echo '<table>';
}
?>
Now my other pages can call it like
<?php
include './BaseTemplate.php'; // include the file with functions
WritePageBase(); // call the function to echo all html code in page
?>
which reduces a lot of html code which now can be edited by a single file (and all other pages using it will change too).
If I have a piece of code that reads a chunk of HTML from a txt file and then echos that html onto the page, how can I accomplish the same task, but when there is PHP inside of the txt file?
ex:
this is the file being read:
<?php
$filecontent = // read some other file
echo($filecontent);
?>
and this is the page that is reading the file:
<?php
$code1 = //reading the above file
?>
<html>
<?php echo($code1); ?>
</html>
When you want to process files containing PHP code you need to use include instead of echo.
<?php include('your_php_file_name'); ?>
If you have the contents of the file in a string you are in a tough spot because the only way to process the code is eval, and in addition you have to properly set up any environment that the code requires. eval itself should be avoided, and the latter is impossible to do in the general case.
Use include instead of echo:
<?php include($file_that_contains_php); ?>
you need to include the first file and echo statement in the first file will get executed.
<html>
<?php require_once("firstfile.php"); ?>
You need to echo htmlentities($code1), because when you echo then browser will not show it contents, because it try to parse it as a html tag, but htmlentities will encode to safe html output this characters.
If you want to evaulate the code, then you need eval($code1) or include it.