我是PHP新手。我有一个代码文件,其中包含php和html代码。在我的代码中,我通过打印了一个HTML页面
<script type="text/javascript">
window.print();
</script>
我在打印页面上使用了一些CSS,比如设置页面大小等。但问题是,如果页面上的内容增加,其结果将破坏页面的格式。我想限制内容只能在一个页面上。有可能吗?
我的CSS
<style>
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: #FAFAFA;
font: 12pt "Tahoma";
}
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.page {
width: 210mm;
min-height: 297mm;
padding: 20mm;
margin: 8mm auto;
border: 1px #D3D3D3 solid;
border-radius: 5px;
background: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.subpage {
padding: 1cm;
border: 5px solid;
height: 257mm;
outline: 2cm #FFEAEA solid;
}
@page {
size: A4;
margin: 0;
}
@media print {
html, body {
width: 210mm;
height: 297mm;
}
.page {
margin: 0;
border: initial;
border-radius: initial;
width: initial;
min-height: initial;
box-shadow: initial;
background: initial;
page-break-after: always;
}
hr {
display: block;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 1px;
border-top: 2px solid #009;
}
}
</style>
您可以使用单词计数。。。我只是在空间上把它分解,所以它显然不是一门精确的科学,但它可能适用于大多数情况。
<script>
(function($){
$(function(){ //document.ready
var data = $("#myContent").text();
var arr = data.split(' ');
var count = arr.length;
runResize(count);
$( window ).resize(runResize(count));
}); /end document ready
function runResize(count) {
if (count > 500) {
$("#myContent").css('font-size', '90%');
} else if (count > 1000) {
$("#myContent").css('font-size', '80%');
} else if (count > 1500) {
// etc..
} else {
$("#myContent").css('font-size', '100%');
}
};
})(jQuery);
</script>
在"静态文件"下创建以下.htaccess文件:
Order Deny,Allow
Deny from all
Allow from 000.000.000.000
<?php
session_start();
session_regenerate_id();
if((!isset($_SESSION['username']))&&(!isset($_SESSION['name']))&&(!isset($_SESSION['role']))){ // if there is no valid session
header("Location: login.html");
}
if($_SESSION['role']=='1'){
$login=$_SESSION['name'];
}
if($_SESSION['role']=='0'){
$login='Hello '.$_SESSION['name'].' you have successufully logged in as User!';
}
?>
- 使用会话进行此类限制
- 通过检查用户的类型来授权用户
- 如果未经授权,则将它们重定向到某个错误显示页面