I have one board.php file that displays a board on my web page. This file includes once a boardEngine.php file which has every variables and matrix initialized, plus every function needed for computing.
I put a form in my board.php so that I can enter my next move on the board. board.php code goes like this:
<!doctype html>
<html>
<body>
<?php
include_once('boardEngine.php');
?>
<div id='board'>
<?php
if (isset($_GET['move'] )) {
checkMove($_POST['queryMove']); // checkMove is from boardEngine.php
}
printBoard(); // function from boardEngine.php
?>
</div>
<form id="moveForm" action="board.php?move" method="post" >
<input type="text" name="queryMove" placeholder="form: 'e2f3' (e2 to f3)" required> </p>
<input type="submit" value=">move!<" >
</form>
</body>
The problem is that when I submit the move, board.php is reloaded with a set $_GET['move']. Since it is reloaded, it seems like boardEngine.php gets included again, and every positions in the matrix are initialized.
As I understand the thing so far, the move is submitted, board.php is reloaded, boardEngine.php is included another time with every position being reset, then because the $_GET['move'] variable has been set through the form, one move will be computed. Once a new move is submitted, the board will be reset and the last move will be considered, and so on.
Am I wrong? How can I solve this problem?
Edit 1: Here is the look of my boardEngine.php code:
<?php
define("PAWN", 10);
define("KNIGHT", 20);
define("BISHOP", 30);
define("ROOK", 40);
define("QUEEN", 50);
define("KING", 100);
define("B_PAWN", -10);
define("B_KNIGHT", -20);
define("B_BISHOP", -30);
define("B_ROOK", -40);
define("B_QUEEN", -50);
define("B_KING", -100);
$board = array(
array("", 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'),
array( 1, B_ROOK, B_KNIGHT, B_BISHOP, B_QUEEN, B_KING, B_BISHOP, B_KNIGHT, B_ROOK),
array(2, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN, B_PAWN),
array(3, 0, 0, 0, 0, 0, 0, 0, 0),
array(4, 0, 0, 0, 0, 0, 0, 0, 0),
array(5, 0, 0, 0, 0, 0, 0, 0, 0),
array(6, 0, 0, 0, 0, 0, 0, 0, 0),
array(7, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN),
array(8, ROOK, KNIGHT, BISHOP, QUEEN, KING, BISHOP, KNIGHT, ROOK)
);
function checkMove($query) {
global $board;
if(strlen($query) != 4) {
return "Wrong query!";
}
//...
// Next modfy the $board positions according to rules
}
function printBoard() {
// ...
}
http is a stateless protocol, which means that the script will run all over again for each request. And posting a form creates a new request.
You're gonna have to persist your game's state somehow. $_SESSION is a good idea, as Barmar suggested too.
EDIT: Since you posted your board engine, and just to get started, do the following:
1) Add a session_start(); at the beginning of your code
2) Replace the $board=.... part with `
if(!isset($_SESSION['board']))
$_SESSION['board']=.......
3) Replace every occurence of $board in your code with $_SESSION['board']
How does BoardEngine.php look?
Why not make it a Class? Something like this:
class BoardEngine {
//You can remove the construct function below, if you don't need it
function __construct(argument)
{
//Constructor code here if needed
}
public function printBoard()
{
# function code here...
}
public function checkMove($var)
{
# function code here...
}
public function yetanotherone()
{
# function code here...
}
}
You can then put all your "engine" logic in there.
And in your board.php:
<?php
require_once('BoardEngine.php');
$boardEngine = New BoardEngine();
if (isset($_GET['move'] )) {
$boardEngine->checkMove($_POST['queryMove']); // checkMove is from boardEngine.php
}
$boardEngine->printBoard(); // function from boardEngine.php
?>
<div id='board'>
</div>
<form id="moveForm" action="board.php?move" method="post" >
<input type="text" name="queryMove" placeholder="form: 'e2f3' (e2 to f3)" required> </p>
<input type="submit" value=">move!<" >
</form>
</body>
To save moves on each reload, I would also suggest using $_SESSION.
Or in your BoardEngine class:
private $lastmove;
public function setLastMove($value)
{
$this->lastmove = $value;
}
public function getLastMove($value)
{
return $this->lastmove;
}
Now in your board.php you can set the last move with:
$boardEngine->setLastmove($var);
get it last move with:
$boardEngine->getLastmove();
EDIT: To clerify:
To save last move as a $_SESSION and echo it out:
$_SESSION['lastmove'] = $boardEngine->getLastmove();
echo $_SESSION['lastmove'];
Firstly, don't say
board.php?move in the action. It is better to specify get variables with values.
Change it to board.php?move=yes
Then,
if(isset($_GET['move'])) if($_GET['move']==="yes") include_once('boardEngine.php');
Related
When I try to print variable "$ime", it just prints "Student: " on pdf file.
I have tested it on html and it works fine displaying whole thing as is should.
Sql result is not empty and it's just one row that displays name and last name. So normal output should be "Student: John Doe"
// Page header
function Header()
{
$db2 = new dbObj();
$connString2 = $db2->getConnstring();
mysqli_set_charset($connString2,'UTF-8');
$aaa = mysqli_query($connString2, "SELECT s.ime,s.prezime FROM Student s WHERE s.mbr='".$mbr."'") or die("database error:". mysqli_error($connString2));
$row=mysqli_fetch_row($aaa);
$ime ="Student: ".$row[0]." ".$row[1];
// Logo
$this->Image('img/logo.png', 85, 15, 30, '', 'PNG', '', 'T', false, 300, 'C', false, false, 0, false, false, false);
$this->SetFont('Arial','B',13);
// Move to the right
$this->Cell(80);
// Title
$this->SetFont('Arial','B',15);
$this->Cell(20,80,'Lista polozenih ispita',0,0,'C');
$this->Ln(10);
$this->Cell(80);
$this->SetFont('Arial','B',10);
$this->Cell(20,80,$ime,0,0,'C');
// Line break
$this->Ln(50);
}
Edit: It's not about variable scoping I have tried but it doesn't affect it in any way.
Following is my code which prints "HELLO", then a dotted line. This thing gets repeated 50 times. Everything is working fine but when 2nd page starts, dotted lines disappear. What modification is required in this code?
<?php
require("fpdf.php");
class PDF extends FPDF
{
function SetDash($black=null, $white=null)
{
if($black!==null)
$s=sprintf('[%.3F %.3F] 0 d',$black*$this->k,$white*$this->k);
else
$s='[] 0 d';
$this->_out($s);
}
}
$pdf = new PDF('P', 'mm', 'A4');
$pdf->AliasNbPages();
$pdf->AddPage();
$margin = 0;
$pdf->SetFont('Arial','B',12);
for ($i = 0; $i < 50; $i++)
{
$pdf->Cell(90, 10, "Hello", 0, 1);
$pdf->SetDrawColor(0,0,0);
$pdf->SetDash(2,2);
$margin = $margin + 10;
$pdf->Line(10,$margin,200,$margin);
}
$pdf->Output();
?>
You're incrementing the value of your $margin variable by 10 after each line even if a page break occurs in the middle of the loop. Thus, the top margin of the first line on the second page will be 10 millimeters greater than the top margin of the last line on the first page.
You need to reset the margin when a new page is added.
A solution for this problem would be to override FPDF's AcceptPageBreak method. This method intercepts the adding of a new page when the bottom of a page is reached.
class PDF extends FPDF
{
var $lineY = 0;
// ...
function AcceptPageBreak()
{
$this->lineY = 0;
return parent::AcceptPageBreak();
}
}
Then, in your loop, you can do:
$pdf->Line(10, $pdf->lineY, 200, $pdf->lineY);
I am new to web development and I am trying to put CAPTCHA into my website. I am stuck at this. And I couldn't find any help.
The following is my Form code:
<tr>
<td>
<img src="html-contact-form-captcha/captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
</td>
</tr>
<tr>
<td align="right"><b> Enter Image Text </b></td>
<td><input placeholder="Enter the code above here" id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</td>
</tr>
And on this same page I am trying to validate this CAPTCHA by the following code:
var cde = document.getElementById('6_letters_code');
if( cde.value == "" ||
($_SESSION['6_letters_code'] != $_POST['6_letters_code']) ) {
alert( "Code Matched!" );
//alert( "Code Doesn't Match! \n Code Not Entered!" );
return false;
}
And this is where I am getting my CAPTCHA: (captcha.php)
session_start(); // Staring Session
$captchanumber = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz'; // Initializing PHP variable with string
$captchanumber = substr(str_shuffle($captchanumber), 0, 6); // Getting first 6 word after shuffle.
$_SESSION["code"] = $captchanumber; // Initializing session variable with above generated sub-string
$image = imagecreatefromjpeg("bj.jpg"); // Generating CAPTCHA
$foreground = imagecolorallocate($image, 175, 199, 200); // Font Color
imagestring($image, 5, 45, 8, $captchanumber, $foreground);
header('Content-type: image/png');
imagepng($image);
Any help would be appreciated.
Thank you in advance.
In Javascript
If you want to evaluate that the captcha is correct in Javascript, which runs in your browser after the page was generated by PHP on the server, then Javascript will have to have the means to check it.
For this you have to use a session, in which you can store the captcha value. Use these steps:
At the start of the PHP file, that generates your form, you should select a captcha code. You store this in a session variable.
You produce a hash of the captcha in PHP and put it in a hidden field of the form. Give this field a proper id, so you can find it with Javascript.
$hash = sha1($captcha); // this is PHP code
Generate the image of the captcha, using the stored session variable.
Regrettably Javascript does not have any native hash algorithm. Other people have solved this:
http://caligatio.github.io/jsSHA/
So now you can also make a hash of the captcha, that was entered by the user into the form, in Javascript. All you need to do is to check it against the hash that PHP has put in the hidden field in the form. If they match the Captcha was correct.
As you can see, this is not really easy.
In PHP
It is easier to do the check in PHP after the form was submitted. I think I can assume your captcha.php works. In that you store $captchanumber in the session of the user. That was a good idea.
So you make the form, put the captcha in it, and let the user submit it. The check will now be done in PHP, like this:
$captchaNumber = $_SESSION['code'];
$userNumber = $_POST['6_letters_code']; // a name starting with number? eh??
if ($captchaNumber == $userNumber)
{
<.... the user did it correctly ....>
}
else
{
// it was the wrong code, back to the form
header('Location: '.<... url of form ...>);
}
The header() function should be used before any output. For starters I would suggest to submit the form to another PHP script. Once that works you can try an merge the form script and the submission script into one PHP script.
Please try the below code. I hope it work. I tried to write the code from scratch:-
<?php session_start();
// Staring Session
$im = imagecreate(90, 30);
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 0);
$captchaKey = substr(md5(time()), 0, 5);
$_SESSION["code"] = $captchaKey;
imagestring($im, 45, 20, 5, $captchaKey, $textcolor);
//header("Content-type: image/png");
$save = "captcha.png";
$x1 = imagepng($im, $save);
?>
<script>
function checkCaptcha() {
var cde = document.getElementById('6_letters_code');
if( cde.value == '<?php echo $_SESSION['code']; ?>
' ) {
alert( "Code Matched!" );
//alert( "Code Doesn't Match! \n Code Not Entered!" );
return false;
} else {
alert('Code not matched!')
}
}
</script>
<tr>
<td><img src="captcha.png" id='captchaimg' >
<br>
</td>
</tr>
<tr>
<td align="right"><b> Enter Image Text </b></td>
<td>
<input placeholder="Enter the code above here" id="6_letters_code" name="6_letters_code" type="text">
<br>
<button onclick="checkCaptcha()">
Click to check
</button><small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small></td>
</tr>
I've been struggling with the header and footer data for quite some time now and thought it was time to ask it here on the forum.
What I'm trying to do is decide that if a page is added if the header / footer should be added or not. so code-wise I want to set the header/footer to on or off when adding a page.
I've tried to manipulate the function AddPage by setting an extra argument $setFooterHeader which default is set to true. And then trying to set this argument to false whenever I do an addPage('','',false); but it ignores it for some reason and I can't figure out why.
If I set the default value of the argument to false in the function itself it works like a charm, but when I try to do it in my script and set it as an argument, it totally ignores it.
Here's a code snippet of the fpdf.php file (function addPage)
function AddPage($orientation='', $size='', $setHeaderFooter=true)
{
// Start a new page
if($this->state==0)
$this->Open();
$family = $this->FontFamily;
$style = $this->FontStyle.($this->underline ? 'U' : '');
$fontsize = $this->FontSizePt;
$lw = $this->LineWidth;
$dc = $this->DrawColor;
$fc = $this->FillColor;
$tc = $this->TextColor;
$cf = $this->ColorFlag;
if($this->page>0)
{
// Page footer
if ($setHeaderFooter == true)
{
$this->InFooter = true;
$this->Footer();
$this->InFooter = false;
// Close page
$this->_endpage();
}
}
// Start new page
$this->_beginpage($orientation,$size,$setHeaderFooter);
// Set line cap style to square
$this->_out('2 J');
// Set line width
$this->LineWidth = $lw;
$this->_out(sprintf('%.2F w',$lw*$this->k));
// Set font
if($family)
$this->SetFont($family,$style,$fontsize);
// Set colors
$this->DrawColor = $dc;
if($dc!='0 G')
$this->_out($dc);
$this->FillColor = $fc;
if($fc!='0 g')
$this->_out($fc);
$this->TextColor = $tc;
$this->ColorFlag = $cf;
// Page header
if ($setHeaderFooter == true)
{
$this->InHeader = true;
$this->Header();
$this->InHeader = false;
}
// Restore line width
if($this->LineWidth!=$lw)
{
$this->LineWidth = $lw;
$this->_out(sprintf('%.2F w',$lw*$this->k));
}
// Restore font
if($family)
$this->SetFont($family,$style,$fontsize);
// Restore colors
if($this->DrawColor!=$dc)
{
$this->DrawColor = $dc;
$this->_out($dc);
}
if($this->FillColor!=$fc)
{
$this->FillColor = $fc;
$this->_out($fc);
}
$this->TextColor = $tc;
$this->ColorFlag = $cf;
}
Below is a code snippet of my PHP script which uses FPDF
/** PHP FPDF */
require_once 'classes/FPDF/fpdf.php';
require_once 'classes/FPDI/fpdi.php';
class PDF extends FPDI
{
function Header()
{
$this->SetFont( 'Arial', 'B', 18 ); //set font to Arial, Bold, and 16 Size
//create heading with params
//0 - 100% width
//9 height
//"Page Heading" - With this text
//1 - border around it, and center aligned
//1 - Move pionter to new line after writing this heading
//'C' - center aligned
$this->Cell( 0, 9, 'Page Heading', 1, 1, 'C' );
$this->ln( 5 );
}
function Footer()
{
//move pionter at the bottom of the page
$this->SetY( -15 );
//set font to Arial, Bold, size 10
$this->SetFont( 'Arial', 'B', 10 );
//set font color to blue
$this->SetTextColor( 52, 98, 185 );
$this->Cell( 0, 10, 'Footer Text', 0, 0, 'L' );
//set font color to gray
$this->SetTextColor( 150, 150, 150 );
//write Page No
$this->Cell( 0, 10, 'Page No: ' . $this->PageNo(), 0, 0, 'R' );
}
}
// Create new PDF object
$pdf = new PDF('P','mm','A4');
$pdf->addPage('','',false);
// Output pdf file
$pdf->Output('test.pdf','D');
Your help is greatly appreciated!!
I have solved this issue by setting a flag outside the class and use this flag in the header and footer function
The fix is in the page section, not in the addPage function
Just before doing an $pdf->addPage You set the flag as addPage automatically calls the header and footer function.
Here's the correct code (snippet of PHP script which uses FPDF)
/** PHP FPDF */
require_once 'classes/FPDF/fpdf.php';
require_once 'classes/FPDI/fpdi.php';
class PDF extends FPDI
{
function Header()
{
if ($this->header == 1)
{
$this->SetFont( 'Arial', 'B', 18 ); //set font to Arial, Bold, and 16 Size
//create heading with params
//0 - 100% width
//9 height
//"Page Heading" - With this text
//1 - border around it, and center aligned
//1 - Move pionter to new line after writing this heading
//'C' - center aligned
$this->Cell( 0, 9, 'Page Heading', 1, 1, 'C' );
$this->ln( 5 );
}
}
function Footer()
{
if ($this->footer == 1)
{
//move pionter at the bottom of the page
$this->SetY( -15 );
//set font to Arial, Bold, size 10
$this->SetFont( 'Arial', 'B', 10 );
//set font color to blue
$this->SetTextColor( 52, 98, 185 );
$this->Cell( 0, 10, 'Footer Text', 0, 0, 'L' );
//set font color to gray
$this->SetTextColor( 150, 150, 150 );
//write Page No
$this->Cell( 0, 10, 'Page No: ' . $this->PageNo(), 0, 0, 'R' );
}
}
}
// Create new PDF object
$pdf = new PDF('P','mm','A4');
$pdf->header = 0;
$pdf->footer = 0;
$pdf->addPage('','',false);
// Output pdf file
$pdf->Output('test.pdf','D');
I know you found out the awnser already for yourself, but as one of the commenters pointed out this didn't work for me with the footer.
The good news is you can do without setting the external flags. You can use $this->PageNo() to determine whether to include the header and footer or not.
For instance if you'd want to exclude the header and footer on the first page, like I did:
function Footer() {
if($this->PageNo() != 1){
// footer code
}
}
If you'd want to let's say exclude them on several pages and not write an endless if statement you should just put the page numbers to exclude in an array and check with in_array() whether the header and/or footer should be included.
You can define multiple different types of headers and footers by calling functions outside the class:
class PDF extends FPDF {
function Header(){
if(!empty($this->enableheader))
call_user_func($this->enableheader,$this);
}
function Footer(){
if(!empty($this->enablefooter))
call_user_func($this->enablefooter,$this);
}
}
$pdf = new PDF('P');
$pdf->SetTextColor(0);
$pdf->SetFont('Arial','B',10);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Cell(50,6,'Headerless & Footerless page');
$pdf->enableheader = 'header1';
$pdf->AddPage();
$pdf->enablefooter = 'footer1';
$pdf->AddPage();
$pdf->AddPage();
$pdf->enableheader = 'header2';
$pdf->AddPage();
$pdf->enablefooter = 'footer2';
$pdf->Output();
function header1($pdf){
$pdf->Cell(50,6,'Header type 1',1,0,'L');
}
function footer1($pdf){
$pdf->SetY(280);
$pdf->Cell(50,6,'Footer type 1',1,0,'L');
$pdf->Cell(0,6,"Page: {$pdf->PageNo()} of {nb}",1,0,'R');
}
function header2($pdf){
$pdf->Cell(50,6,'Header type 2',1,0,'L');
}
function footer2($pdf){
$pdf->SetY(280);
$pdf->Cell(50,6,'Footer type 2',1,0,'L');
$pdf->Cell(0,6,"Page: {$pdf->PageNo()} of {nb}",1,0,'R');
}
The trick to footers is that the footer is added when the next page is created, with the last footer being added when the output is closed.
Therefore, you have to define the header before the page is added, and the footer afterwards but before the next page.
I am having a problem with a gd library issue. When I use the following code
<script type="text/javascript">
$.fn.infiniteCarousel = function () {
function repeat(str, num) {
return new Array( num + 1 ).join( str );
}
return this.each(function () {
var $wrapper = $('> div', this).css('overflow', 'hidden'),
$slider = $wrapper.find('> ul'),
$items = $slider.find('> li'),
$single = $items.filter(':first'),
singleWidth = $single.outerWidth(),
visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
currentPage = 1,
pages = Math.ceil($items.length / visible);
// 1. Pad so that 'visible' number will always be seen, otherwise create empty items
if (($items.length % visible) != 0) {
$slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
$items = $slider.find('> li');
}
// 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
$items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
$items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
$items = $slider.find('> li'); // reselect
// 3. Set the left position to the first 'real' item
$wrapper.scrollLeft(singleWidth * visible);
// 4. paging function
function gotoPage(page) {
var dir = page < currentPage ? -1 : 1,
n = Math.abs(currentPage - page),
left = singleWidth * dir * visible * n;
$wrapper.filter(':not(:animated)').animate({
scrollLeft : '+=' + left
}, 500, function () {
if (page == 0) {
$wrapper.scrollLeft(singleWidth * visible * pages);
page = pages;
} else if (page > pages) {
$wrapper.scrollLeft(singleWidth * visible);
// reset back to start position
page = 1;
}
currentPage = page;
});
return false;
}
$wrapper.after('<a class="arrow back"><</a><a class="arrow forward">></a>');
// 5. Bind to the forward and back buttons
$('a.back', this).click(function () {
return gotoPage(currentPage - 1);
});
$('a.forward', this).click(function () {
return gotoPage(currentPage + 1);
});
// create a public interface to move to a specific page
$(this).bind('goto', function (event, page) {
gotoPage(page);
});
});
};
$(document).ready(function () {
$('.infiniteCarousel').infiniteCarousel();
$("a.pictureThumb").fancybox({
'autoScale' : true,
'autoDimension' : true,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'speedIn' : 300,
'speedOut' : 200,
'hideOnOverlayClick' : true,
'hideOnContentClick': false
});
});
</script>
With this as the image generator, the only thing that comes out is what looks like programming code instead of an image. This script worked with a different scroller, but since I put this new scroller script (seen above), I am having problems with it generating an image (IE it just shows the loading icon), FireFox actually shows the programming code.
Here is the code that is making the call to the GD function:
<div class="infiniteCarousel">
<div class="wrapper">
<ul>
<?php
do { ?>
<li><a class="pictureThumb" href="picture.php?imgID=<?php $pieces = explode('_', $row_rsPictures['PictureFile']); echo $pieces[0]."_".$pieces[1]."_".$pieces[2]; if ($pieces[3] == "NN"){ echo "_NN_".$pieces[4]."_".$pieces[5];; } else { echo "_".$pieces[3]."_".$pieces[4]; } ?>&thumb=Y" title="<a href='addToCart.php?T=Pic?ID=<?php echo $row_rsPictures['PictureID']; ?>' target='_parent' style='color:#fe6d00' >Add This Image To Your Shopping Cart</a><br><?php echo $row_rsPictures['BoatName'];if($row_rsPictures['BoatNumber'] != "") {
echo " #".$row_rsPictures['BoatNumber'];
} ?><br>driven by: <?php echo $row_rsPictures['DriverName']; ?> at the <?php
$AssocName_array = explode('_', $row_rsPictures['Acronym']);
$AssocName = $AssocName_array[0];
if ($AssocName == "Various") {
$AssocName = "";
}
if ($row_rsPictures['DateTo'] != ""){
$EventYear = date("Y", strtotime($row_rsPictures['DateTo']));
}
else { $EventYear = "";
}
echo $EventYear." ".$AssocName." ".$row_rsPictures['EventName'];?><br>Picture Viewed (<?php echo $row_rsPictures['Views']; ?>) since posted on <?php echo date("n-j-Y", strtotime($row_rsPictures['DatePosted'])); ?>" rel="group">
<img src="../images/gallery/<?php $raceYear = explode('_', $row_rsPictures['EventOverlay']); echo $raceYear[0]; ?>/<?php echo $row_rsPictures['EventOverlay']; ?>/thumb/<?php echo $row_rsPictures['PictureFile']; ?>.jpg" alt="FileName: <?php echo $row_rsPictures['PictureFile'];?>"></a></li>
<?php
} while ($row_rsPictures = mysql_fetch_assoc($rsPictures));
mysql_data_seek($rsPictures, 0);
?>
</ul>
</div>
</div>
and the separate php file that generates the image.
<?php
$filename = explode("_", $_GET['imgID']);
$folder = $filename[0];
$subFolder = $filename[0]."_".$filename[1]."_".$filename[2];
if($filename[3] == "NN") {
$subFolder = $subFolder."_NN";
}
$shot = "../images/gallery/".$folder."/".$subFolder."/".$_GET['imgID'].".jpg";
$watermark = "../images/gallery/watermark.png";
header("Content-type: image/jpg");
$photoImage = ImageCreateFromJPEG($shot);
ImageAlphaBlending($photoImage, true);
$logoImage2 = ImageCreateFromPNG($watermark);
$im = imagecreatetruecolor(800, 16);
$im2 = imagecreatetruecolor(800, 10);
$white = imagecolorallocate($im, 255, 255, 255);
//imagefilledrectangle($photoImage, 0, 0, 796, 15, $white);
$grey = imagecolorallocate($im2, 128, 128, 128);
$red = imagecolorallocate($im2, 255, 0, 0);
//$im = imagecreatetruecolor(796, 25);
$text = $_GET['imgID'];
$text2 = 'COPYRIGHT 1997 - 2011 - DRAGBOATS.COM - ALL RIGHTS RESERVED';
$text3 = '^ THIS BAR WILL NOT APPEAR ON PURCHASED PRINTS ^';
//$black = imagecolorallocate($photoImage, 0, 0, 0);
imagestring($im, 2, 10, 1, $text, $white);
imagestring($im, 2, 440, 1, $text2, $white);
imagestring($im2, 1, 290, 1, $text3, $white);
ImageCopy($photoImage, $im, 0, 0, 0, 0, 800, 16);
ImageCopy($photoImage, $im2, 0, 17, 0, 0, 800, 10);
ImageCopy($photoImage, $logoImage2, 0, 0, 0, 0, 800, 525);
ImageJPEG($photoImage); // output to browser
ImageDestroy($photoImage);
ImageDestroy($logoImage2);
?>
Somewhere there is a conflict that is causing the problem and I can't find it.
Any help is appreciated.
The actual page can be found at http://randykrohn.com/gallery/pictures_test.php?BoatID=881
It appears you're outputting the raw image data (the bytes in the .jpg) file into the gallery popup, with an innappropriate header so that the imgae is being interpreted as text and not an image.
If that last chunk of code under "... the call to GD function" is all in one file, that would explain why. You're outputting a chunk of html, followed by the raw image data, which then gets inserted into the gallery popup. The Content-type header cannot take effect as you've already output some html. If you check your error logs (and/or actually enable errors/warnings), you'd no doubt see the usual "cannot modify headers, output started at line XXX" warnings from PHP.
Try to set php memory limit to 96M (128M - recommended) in php.ini file. If you have no access to that file simply add ini_set('memory_limit', '128M'); to your php file. It must help to solve the issue.
Didn't help, but figured it out on my own. Needed to tell FancyBox to open the link explicitly as an image (ie: fancybox({'type' : 'image'}); Alls well now! Thanks for you help guys!