Fatal error: Class 'TCPDF' not found - php

I am generating the PDF file but facing the trouble. Can anybody tell me the solution of this error. Below is the code that I used for that. I include the tcpdf for this but there is a fatal error that saying that tcpdf file in not available or we can say not found.
<?php
$tcpdf_include_dirs = array(realpath('tcpdf.php'), '/usr/share/php/tcpdf/tcpdf.php', '/usr/share/tcpdf/tcpdf.php', '/usr/share/php-tcpdf/tcpdf.php', '/var/www/tcpdf/tcpdf.php', '/var/www/html/tcpdf/tcpdf.php', '/usr/local/apache2/htdocs/tcpdf/tcpdf.php');
foreach ($tcpdf_include_dirs as $tcpdf_include_path) {
if (#file_exists($tcpdf_include_path)) {
require_once($tcpdf_include_path);
break;
}
}
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // Create New PDF Doc
$pdf->SetCreator(PDF_CREATOR); //Setup a document information
include("db_connection.php");
$isql = mysqli_query($con, "SELECT * FROM `cpdf`") OR die("Data Select problem: ".mysqli_error($con));
$num = mysqli_num_rows($isql);
$pdf->AddPage(); //Add new page
while($row = mysqli_fetch_array($isql)){
$firstname = $row['fname'];
$lastname = $row['lname'];
$fullname = $firstname ." ".$lastname;
?>
<html>
<head>
<title>PDF Page</title>
</head>
<body>
<form>
<div>
<div><img style="width: 100%; height: 20%" src="image/FlZJRBAXRlweb design.idevtechnolabs.socialsigna.l.JPG"/></div>
<div style="width: 100%; height: 30%">
<table style="float: right; border: 2;">
<tr style="width: 10%;"><td style="text-align: left;"><?php echo $fullname; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['add1']; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['add2']; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['city']; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['state']; ?></td></tr>
<tr style="width: 20%;"><td style="text-align: left;"><?php echo $row['date']; ?></td></tr>
</table>
</div>
<div style="float: left; height: 10%;">
<b>Subject:</b> <?php echo $row['subject']; ?>
</div>
<div style="height: 40%; width: 100%;">
<p style="text-align: justify;">Hey, <br /><br /> Mr. <?php echo $fullname; ?>. This is to inform you that a day after tomorrow is the last date of your invoice payment. This is a reminder notice to pay your <?php echo $row['bill']; ?> invoice amount our nearest store and takes advantage of our services.</p>
<p style="text-align: justify; text-indent: 4em;">We request you to pay your <?php echo $row['bill']; ?> Bill as soon as possible.</p>
<span style="float: right;">Thank you,<br /><img src="#"/></span>
</div><?php $pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);
}
$pdf->Output('example_002.pdf', 'I'); ?>
</div>
</form>
</body>
</html>

As a first step, comment out the first seven lines of code and add one new line of code that includes tcpdf.php using the full path to the file. If that doesn't work then you should check the contents of the tcpdf.php file to make sure that it hasn't been corrupted somewhere along the way. That is, make sure it still contains the code that declares the TCPDF class.
If that works then comment out the hard-coded include statement, uncomment the seven lines that were commented out earlier and add an echo statement to print out the $tcpdf_include_path variable during each iteration of that loop. As long as one of those paths match the hard-coded path that presumably worked earlier, then your code should work fine.
Finally, and I highly doubt this is the case, but if you happened to have a case-sensitive file system and you happened to have the tcpdf.php file saved as TCPDF.PHP, for example, then that might contribute to the problem. I'm only mentioning that possibility for completeness to the answer, but it is highly unlikely, especially based on the information you provided, that this is the problem in your case.

Related

Why is my PHP botched through one host, but rendered perfectly fine through another?

I created a quirky little random-color generator in a class last year while learning php as a beginner on the server the teacher had set up for students:
http://tony.rop.launchbrigade.com/random_squares.php
Recently, I bought a domain with Namecheap and put a small LAMP server on a Raspberry pi. I literally copied and pasted the random_squares.php into VIM at
http://modjo.xyz/Colorful_Squares.php
I did notice that the php seemed to be processed a lot more on the modjo.xyz server, after inspecting the source.
So, my main question is, what do Framesets do, and why does it so drastically alter the PHP? In the source, the lower part of the function that generates the squares was pasted above the first part of the function. I haven't touched php in a while, but I'm assuming this has to do with either Namecheap, or the DOCTYPE declaration, or both. Is there a way to not have my code altered by Namecheap?
Here's the full page for clarity (No CSS or anything, all self-contained):
<HTML>
<STYLE>
TD {
padding: 0px;
border: 5px solid inherit;
margin: 10px;
border-radius: 20px;
}
</STYLE>
<TITLE>Randomly Colored Squares</TITLE>
<BODY>
<DIV align="left" bgcolor="#FF00FF">
<TABLE bgcolor="DDDDDD" border="0" cellpadding="10" width="100%" height="10%">
<TR>
<TD colspan="2">
<CENTER><head><font face="helvetica" size="20" color="EEE"><b>Tony's Interweb Page</b></font></head></CENTER>
</TD>
</TR>
</TABLE>
</DIV>
<CENTER><H2><font face="helvetica" size="12" color="EEE"><b>Randomly Colored Rectangles!</b></font></H2></CENTER>
<TABLE border="0" cellpadding="10" width="100%">
<?php
$rowcount = 9;
$colcount = 5;
$fitwidth = "150px";//(100/$colcount);
for ($i = 0; $i < $rowcount; $i++)
{
echo '<TR height="200px" margin="10px">';
for ($x = 0; $x < $colcount; $x++)
{
$color = substr(md5(rand()), 0, 6);
echo '<TD width="'.$fitwidth.'%" bgcolor="'.$color.'" margin="10px"><font face="helvetica" size="12" color="FFFFFF"><b>'.$color.'</b></font></TD>'."\n";
}
echo '</TR>';
}
?>
</TABLE>
</BODY>
</HTML>

get first object from result array php

I have view file on my app there is code array I want to get first object of that array without going in loop.
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
$result is array of object I'm getting from a form. In below you can clearly see I'm chunking it to 3 more array and looping though individual objects and getting their details to html for example.
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
I want to get the first object details let's say want get $product->product_name of first object of result array without going in loop how to achieve that.
here is complete view file code.
<!DOCTYPE html>
<html class="bg-black">
<head>
<meta charset="UTF-8">
<title><?php if(isset($title)) echo $title.' | '; ?> Sales agent management software (SAMS) </title>
<style>
body{
font-size: 9px;
margin: 20px;
}
th,td,p,div,table,h3{margin:0;padding:0}
#page { margin: 20px; }
.header{
border-bottom: 0px solid #dddddd;
text-align: center;
position: fixed; top: 0;
}
.footer { position: fixed; bottom: 0px; text-align: center }
.pagenum:before { content: counter(page); }
</style>
</head>
<body>
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<div class="footer">
Page: <span class="pagenum"></span>, creation time : <?php echo date('l jS \of F Y h:i:s A') ?>, create by: <?php echo user_full_name(singleDbTableRow(loggedInUserData()['user_id'])); ?>, $ Rate : Rs. <?php echo $usd; ?> </div>
<br />
<div class="box-body">
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
<tr>
<th><FONT SIZE=12>LKR</FONT></th>
<td><FONT SIZE=14><?php $lkr = get_selling_price($product);
echo number_format(round($lkr, get_option('round_precision')) ); ?></FONT>
</td>
</tr>
<tr>
<th> <FONT SIZE=12>US $</FONT></th>
<td><FONT SIZE=14><?php echo number_format(round(lkr_to_usd($lkr), get_option('round_precision')) ); ?></FONT></td>
</tr>
</table>
<?php $GLOBALS['a']= $product->product_id; ?>
</div>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div><!-- /.box-body -->
</body>
</body>
</html>
ok man as i said u need to change your way of writing codes but about your specific question use this:
$result = array('a', 'b', 'c', 'd', 'e');
reset($array);
$first = current($array);
you can check this:
http://php.net/manual/en/function.reset.php
http://php.net/manual/en/function.current.php
But still about your way of coding. u should soon go to MVC or such ways of programming so u should separate your view and coding logics
like u may have a page like view_profile.php which is going to show user's information. in regular coding u have this:
view_profile.php:
<?php session_start();
// you check sessions to see if the user is logged in and has the right to view this page.
// like:
if ($_SESSIONS['is_user_logged_in']){
$username=$_SESSIONS['username'];
$name=$_SESSIONS['name'];
// ....
}else{
header('location: ./login.php');// if user is not authenticated u redirect to login page
exit();// prevents the rest of codes to be shown and executed
}
?>
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
But in a better way u can do it like this:
you have files like
'view_profile.htm' // holds the HTML
'view_profile.php // holds the PHP logic
'inc.php' // holds some useful functions that help you in writing PHP logic
view_profile.htm
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
inc.php
<?php
function ses_start(){
if(!session_id()){
session_start();
}
}
function ses_get($key){
ses_start();
if(!empty($_SESSION[$key])){
return $_SESSION[$key];
}
return NULL;
}
function ses_set($key,$val){
$_SESSION[$key]=$val;
}
function is_user_loggedin(){
ses_start();
if(!empty(ses_get('is_user_loggedin')){
return true;
}
return false;
}
function go($to){
header('location: '.$to);
exit();
}
//and lots of useful functions that help u connect and work with data base.
view_profile.php
<?php
include('inc.php');
if(is_user_loggedin(){
$username=ses_get('username');
$name=ses_get('name');
//...
}else{
go('login.php);
}
include('view_profile.html); // and u call the .htm file that holds the HTML the view file)
?>
this was a simple sample of separating codes logic(php codes) from views(html tags)
and also u may search about MVC Model-View-Controller and try working with simple MVC frameworks.

PHP code being commented out

I'm using CentOS 6.4 with apache installed. I have a single php file called cmsSearch.php. At the top of the file I have PHP that executes fine (queries a Sphinx Search index). But, any php I try to run in the HTML that is below (trying to run a foreach and populate a table with the results of the Sphinx Search) just gets commented out when I view the page in the console (Chrome). Here is the whole cmsSearch.php file:
<?php
require("sphinxapi.php");
if($_POST['keyword'])
{
$keyword = $_POST['keyword'];
$client = new SphinxClient();
$client->SetMatchMode(SPH_MATCH_ANY);
$result = $client->Query($keyword, "staffDirectoryMember");
if(!$result)
{
print "ERROR: " . $client->GetLastError();
}
else
{
var_dump($result["matches"]);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Sphinx Test</title>
<style>
.container
{
border: solid 1px black;
height: 350px;
width: 700px;
margin: auto;
padding: 5px;
}
.output
{
margin-top:20px;
border: solid 1px red;
height: 200px;
}
</style>
</head>
<body>
<?echo "TEST"; ?>
<div class="container">
<div>
<form method="post" action="cmsSearch.php">
<input type="text" name="keyword">
<input type="submit" value="Search">
</form>
<div class="output">
<? echo "test2"; ?>
<table>
<thead>
<tr>
<th>ID</th>
<th>Weight</th>
<th>ClientId</th>
<th>DomainId</th>
<th>ContentTypeId</th>
</tr>
</thead>
<tbody>
<?
echo "Above for loop";
foreach($result["matches"] as $match)
{
echo "Print from for loop:";
var_dump($match);
?>
<!-- <tr>
<td><?=$match[id]?></td>
<td><?=$match[weight]?></td>
<td><?=$match[attrs][clientid]?></td>
<td><?=$match[attrs][domainid]?></td>
<td><?=$match[attrs][contenttypeid]?></td>
</tr> -->
<?}
echo "After for loop";
?>
</tbody>
</table>
</div>
</div>
</div>
Not sure why the php executes at the top fine (i can echo out and the var dump works), but then any php put in the HTML just shows as comments and doesn't do anything. Anyone have an idea?
Your PHP contained inside the HTML is using short tags which can be turned off in your php.ini file. Take a look at this directive and make sure it is set to true if you want to use them:
short_open_tag true
http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
Try using <?php to start your PHP blocks, not <?... It's the difference between the blocks of code.

keeping track of pages and mysql_num_rows

Working off my previous question I'm trying to figure out how to achieve what I'm after.
I have an order that gets made. When the time comes to print that order, if the order has more than 25 lines/rows i need to put up from line 26 and create a new page. My question is how would I write that? I was thinking with mysql_num_rows but how can I track that?
How would I break it down, say put rows 0-24 into array1 then put rows 25-49 into array2 and so on? Then put the different arrays into while loops?
Maybe put everything into an array, then split it up?
Here's what I have right now
<?php
if (isset($_POST['CheckBox'])){
$CB = $_POST['CheckBox'];
} else {echo 'Nothing Marked'; die;}
/////////////////////////////////////////
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
#media print{ #page{margin: 5%;} }
body{
background-color: #CCC;
margin:0;
padding:0;
}
#MainWrapper{
margin:0 auto;
width:675px;
height:900px;
background-color:#3CF;
position:relative;
}
#OrderInfo{
width:200px;
height:50px;
background-color:#6C6;
float:left;
font-family:Verdana, Geneva, sans-serif;
font-size:9px;
}
#OrderInfoNotes{
width:475px;
height:50px;
background-color:#6C6;
float:right;
font-family:Verdana, Geneva, sans-serif;
font-size:9px;
}
#LineHeader{
width:675px;
background-color:#C90;
float:left;
}
.OrderLines{
font-family:Verdana, Geneva, sans-serif;
font-size:9px;
padding:0px;
}
.PBA{page-break-after: auto;}
.bigbold{ font-weight:bold; font-size:14px;}
.bigger{font-size:14px;}
</style>
</head>
<body>
<?php
///////////////////////////////////////////
foreach ( $CB as $thekey => $Order_ID )
{
$queryOrderHead = "SELECT * FROM Orders WHERE Order_ID = ".mysql_real_escape_string($Order_ID)."";
$queryOrderLines = "SELECT * FROM Order_LineDetails WHERE Order_LineDetails.Order_ID = ".mysql_real_escape_string($Order_ID)."";
//////////////////////////////////////////
if ($queryRunHead = mysql_query($queryOrderHead)){
//////////////////////////////////////////
// THIS IS THE HEADER OF THE ORDER ///////
//////////////////////////////////////////
while ($info_HEAD = mysql_fetch_array($queryRunHead))
{
$OrderDate_HEAD = $info_HEAD['OrderDate'];
$shippingservice_HEAD = $info_HEAD['shippingservice'];
$OrderNotes_HEAD = $info_HEAD['OrderNotes'];
?>
<div id="MainWrapper">
<!--START ORDERINFO INTO -->
<div id="OrderInfo">
Order ID:<span class="bigbold"><?php echo ' '.$Order_ID; ?></span><br>
<?php echo 'SHIPPER: <span class="bigbold">'.$shippingservice_HEAD.'</span>'; ?><br>
<?php echo 'ORDER DATE: '.$OrderDate_HEAD; ?>
</div>
<div id="OrderInfoNotes">
<?php echo 'NOTES: '.$OrderNotes_HEAD; ?></div>
<!--END ORDERINFO INTO -->
<hr><br>
<div id="LineHeader">
<table class="OrderLines">
<tr class="bigbold">
<td width="300"><u>Product Name:</u></td>
<td width="90"><u>UPC Code:</u></td>
<td width="50" align="right"><u>PID:</u></td>
<td width="75" align="right"><u>QTY:</u></td>
<td width="160" align="right"><u>Packer:</u></td>
</tr>
<?php
}
/////////////////////////////////////////
// THIS IS THE ORDER LINES //////////////
/////////////////////////////////////////
$queryRunLines = mysql_query($queryOrderLines);
while ($info = mysql_fetch_array($queryRunLines))
{
$ProductName_LINE = $info['ProductName'];
$qty_LINE = $info['qty'];
$Product_ID_LINE = $info['Product_ID'];
$UPC_LINE = $info['UPC'];
?>
<tr class="bigger">
<td><?php echo $ProductName_LINE; ?></td>
<td><?php echo $UPC_LINE; ?></td>
<td align="right"><?php echo $Product_ID_LINE; ?></td>
<td align="right"><?php echo $qty_LINE; ?></td>
<td></td>
</tr><tr>
<td colspan="5"><hr></td></tr>
<?php
}
///////////////////////////////////////////////////////////
// END OF ORDER LINES /////////////////////////////////////
///////////////////////////////////////////////////////////
$numRows = 0;
$numRows = mysql_num_rows($queryRunLines);
echo 'Total Rows ('.$numRows.')'
///////////////////////////////////////////////////////////
?><tr>
<td colspan="5" class="center">--- :END: ---</td>
</tr>
</table>
</div>
</div>
<p class="PBA"/>
<?php
} else {
echo mysql_error();
}
}
mysql_close($conn);
?>
</body>
</html>
From looking at your previous question, it appears you want to print the HTML page, not use pagination. Just use a counter variable:
$i = 0;
while ($info = mysql_fetch_array($queryRunLines))
{
$ProductName_LINE = $info['ProductName'];
$qty_LINE = $info['qty'];
$Product_ID_LINE = $info['Product_ID'];
$UPC_LINE = $info['UPC'];
if (!($i % 25)) {
// echo page break every 25 lines
}
// output
$i++;
}
Also take a look at CSS attributes page-break-before/page-break-after. I would also suggest using an HTML to PDF converter. They are easy to use and will make your printed documents consistent across different systems.
What you need is called pagination.
One of the way to do it is, use LIMIT clause in your query.
I would have put up here but there are hundreds of tutorials for pagination in google with good explanation. It would be better if you search by "php pagination" and learn step by step.
you can limit the number of rows returned by your query,
add LIMIT 0, 24 at the end of your query, you will get the first 25 rows.
you can have more details here
Use a variable to store how many rows you want to display and another one to store the current rows being retrieved.
Look up pagination which will give you a better idea. It may not be exactly what you what but will teach you how to limit sql results they way you want.

PHP. session_start() [function.session-start]: Cannot send session cookie error

Im having problem in my web where it works perfectly on my local server which is a WAMPSERVER i can run my website completely but after adding to the web server it give me error saying
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/multisl/public_html/udrivetest/index.php:2) in /home/multisl/public_html/udrivetest/init.php on line 4
init.php
<?php
ob_start();
session_start();
mysql_connect("localhost","***","***");
mysql_select_db('****');
include 'function/user.func.php';
include 'function/car.func.php';
include 'function/image.func.php';
?>
header1.php
<head>
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style4 {
font-size: 16px;
font-weight: bold;
}
.style5 {
font-size: 12px
}
.a {
color:#000000;
text-decoration:none;
}
-->
</style>
</head>
<body>
<div style="margin-left:10px;">U Drive.lk</div>
<div class="style5" style="text-align:right; padding:10px;">
Contact Us | Disclaimer | Site Map</div>
</div>
<div>
<div style="background-image:url(images/Car3.png); border:#FFFFFF; border-style:solid; border-width:2px; border-top:none; border-bottom:none; width:920px; height:450px; margin-left:auto; margin-right:auto;" align="center">
<br/>
<img src="images/Car6.png" width="920px" height="135px" />
<div style="margin-top:-22px; height:22px; margin-left:55px;" align="left"><a class="a">Home</a></div>
<div style="margin-top:-22px; height:22px; margin-left:200px;" align="left"><a class="a">Gallery</a></div>
<div style="margin-top:-22px; height:22px; margin-left:350px;" align="left"><a class="a">Leasing</a></div>
<div style="margin-top:-22px; height:22px; margin-left:490px;" align="left"><a class="a">Testimonial</a></div>
<div style="margin-top:-22px; height:22px; margin-left:640px;" align="left"><a class="a">Forum</a></div>
<div style="margin-top:-22px; height:22px; margin-left:790px;" align="left"><a class="a">FAQ</a></div>
<div style="margin-left:auto; margin-right:auto; margin-top:20px;" >
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','920','height','135','src','Flash/Flash Header2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','Flash/Flash Header2' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="920" height="135">
<param name="movie" value="Flash/Flash Header2.swf" />
<param name="quality" value="high" />
<embed src="Flash/Flash Header2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="920" height="135"></embed>
</object></noscript>
</div>
<div align="left">
<table width="100%" border="0" style="margin-top:10px;">
<tr>
<td width="20%" valign="top" ><div align="left"><img src="images/Buy_men.png" /> <img src="images/Sell_men.png" /> <img src="images/Rent_men.png" /></div>
<div style="color:#FFFFFF;margin-top:-90px; width:38px; margin-left:10px;">Buy</div>
<div style="color:#FFFFFF;margin-top:-18px; width:38px; margin-left:65px;">Sell</div>
<div style="color:#FFFFFF;margin-top:-20px; width:38px; margin-left:115px;"><a style="color:#FFFFFF;">Rent</a></div></td>
<td width="38%"><fieldset style="background-color:#cccccc">
<span class="style4">Quick Search</span>
</fieldset></td>
<td width="42%"><fieldset style="background-color:#cccccc">
<span class="style4">Login</span>
<?php include_once('login.php'); ?>
</fieldset></td>
</tr>
</table>
</div>
</div>
</div>
<div style="margin-left:auto; margin-right:auto; width:920px;">
login.php
<?php
if (logged_in()) {
echo '<br/> View User Profile <br/>Log Out';
} else {
?>
<form action="" method="post">
<table width="100%" border="0" style="margin-top:-5px;" >
<tr>
<td><div align="left">User Name :</div></td>
<td><input type="text" name="Quick_Name" size="25" /></td>
</tr>
<tr>
<td><div align="left">Password :</div></td>
<td> <input type="text" name="PassWord" size="25" /> <input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
Forgot your password / Register User
<?php
}
if (isset($_POST['Quick_Name'], $_POST['PassWord'])) {
$forgotEmail = $_POST['Quick_Name'];
$login_password = $_POST['PassWord'];
if (empty($forgotEmail) || empty($login_password)) {
$errors[] = 'Email and Password required';
} else {
$login = login($forgotEmail, $login_password);
if ($login === false) {
$errors[] = 'Unable to Log you in';
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br/>';
}
} else {
$_SESSION['user_id'] = $login;
header('Location:index.php');
exit();
}
}
?>
index.php
<?php include 'init.php'; include 'widgets/header1.php'; ?>
<div>
</div>
</div>
</body>
</html>
Please Can any one help me out to solve this problem or give me a clue what I am doing here?
Thanks in Advance
In PHP, headers get sent as soon as the page starts to print something - which can occur unintentionally due to whitespace.
Based on your error message (output started at /home/multisl/public_html/udrivetest/index.php:2)
I am guessing this line of index.php:
<?php include 'init.php'; include 'widgets/header1.php'; ?>
appears on line 2 of the file? But you cannot have a line of whitespace above it, it needs to be line 1 since one of the includes is dealing with headers (cookie for session).
Otherwise the blank line 1 is "printing something" - a new line - which sends headers probably before you are intending.
Basically, check all files for not having blank lines above opening tags <?php and don't have blank lines below closing tags ?>.
This is most likely that there exists some whitespace that is sent before the session_start command, try removing the closing PHP tag (?>) and report back the results.
By doing this you remove the possibility of it outputting any invalid whitespace.
There should have some blank space sending back to client. It is a good practise to leave php closing tag ?> if your last line of code is a php code.
Make sure that you dont leave any blank space before and after the php opening tag and php closing tag
You can prevent any output to send to client by using object buffering with ob_start() .
put the ob_start at the very beginning of your php code can save you time.
I would like to consider removing ob_start() from init.php to index.php.
thanks

Categories