Problems referencing file to create a dynamic image

images php coding issues or problems here.

Moderators: macek, egami, gesf

George the Flea
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Jul 26, 2004 10:42 pm
Location: Washington
Contact:

Problems referencing file to create a dynamic image

Postby George the Flea » Wed Jul 28, 2004 12:33 am

I have been having several issues with creating a dynamic image using the <img src="image.php"> method. I would greatly appreciate any help I can get on these things.

Here's the basics of how the site works to explain the context for these problems:

On the main page, you can click three links to choose three different images. Each link opens a pop-up window, with a selection of possible images. The popup checks via session variables if an image has already been chosen, and displays it if so. When a different image is chosen, it reloads the main page with a get command in the url referencing the image (an if statement on the main page checks for this and stores it in the correct session variable). As a result, the main page and the three pop-ups all have session_start() and deal with session variables.

When two or more images have been chosen, the main page is supposed to combine them, and then show the result. Obviously I can't do this right on the page because of the headers already sent issue, I tried making a class which had a display() function, which didn't address the headers thing, and finally settled on a reference to a php page through the image tag as the only way to get it done without messing around with output buffering (since I don't know much about it and wasn't able to find much in the way of explanation online).

Hokay, so. I reference the image creation page like so from the main page:

Code: Select all

<img src="image.php" alt="Whatever">


I cannot use session variables with image.php without totally deleting all the session variables already stored by the main page. I don't understand why this is, but it seems that when I have session_start() at the top of image.php, it creates a totally new session with blank (or missing) variables. Why is this? Is it possible to use session variables on this page without deleting the session inadvertantly?

Before anyone asks, I also tried this code, which has the same problem:

Code: Select all

if (!session_id()) {
     session_start();
}


Is it just impossible to use sessions with a page referenced the way this one is?

The session problem is my main one, but something that might be related is that the image.php file can not find global variables declared on the main page. define("SECURE", true) on the main page, followed by if (!defined("SECURE")) { die(); } in image.php results in the file dying.

My quick fix was to put the image variables in the URL call to image.php (i.e. src="image.php?image=whatever&image2=whichever"), but this is very confining, particularly since I want to be able to add text to the images, which could run into problems as far as URL length goes.

I would greatly appreciate any help that you folks can give me, since these issues with images have been driving me up the wall. I've been unable to find any good fixes in the php manual, and none of the things that I tested worked out. I have only recently started programming PHP, so if there are any resources that I don't know about, I would love a link.

Thank you for your help!

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Postby ruturajv » Wed Jul 28, 2004 1:27 am

quite a long problem... I don't know how much I've understood....

Why do you start session on image.php

call session_start .... on the page where <img > tag is present...

and on the page load, [set|increment|update] session values wheather. the fellow has seen the image or not...

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Wed Jul 28, 2004 6:10 am

I'm not sure what the problem is. It seems pretty strange. I rather doubt ruturajv's suggestion will help much.

Personally, if I were doing this, I wouldn't use sessions. I'd just use JavaScript. Have a number of hidden form fields in the main page, and have the pop-up windows populate those fields via JavaScript.

George the Flea
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Jul 26, 2004 10:42 pm
Location: Washington
Contact:

Postby George the Flea » Wed Jul 28, 2004 2:56 pm

Sorry for my inability to really describe the problem. I don't really understand it myself.

Ruturajv: I don't call session_start() on image.php because this overwrites the session for some reason. However, without calling session_start() on image.php I don't have access to the session values, making a nice little catch 22 if I want to use sessions.

Swirlee: I'll try using JavaScript and hidden forms, although I still like sessions better mainly because then I don't have to keep passing around values that don't change. I suppose if there simply isn't any way around the session glitch that seems to exist with calling the page through the <img> tag that I don't have any other choice but to pass all the values every time and just settle for less efficient code.

I was hoping that someone might have an idea why sessions weren't working properly when the page using them was called through an image tag. Oh well. Off to code some hidden form values.

Thanks for your help!

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Postby ruturajv » Wed Jul 28, 2004 7:57 pm

hey george the flea...

just let me describe some pts, atleast what I've understootd

* When user checks the main page with the image tag, you want to check which particular image has he seen.
* depending upon which image has he seen, you have to do some stuff

George the Flea
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Jul 26, 2004 10:42 pm
Location: Washington
Contact:

Postby George the Flea » Wed Jul 28, 2004 11:06 pm

ruturajv:

Sorry, no. I must have really bungled my explanation. The user is creating an image from several parts. When they have chosen at least two parts, the page displays the combined result. Because I can't just include the image through a function or something (headers already sent, grrrr), I was trying to reference a script to create the image through an <img> tag (i.e. src="image.php"). Image.php creates the image dynamically, but the problem is getting the variables about which images to combine (among other things) to image.php. I tried sessions, but when you start a session on the main page and also on an included page (image.php) the session variables all get erased. I can dynamically create the URL call to image.php and use GET once there, but I intend to have a bunch more variables which would extend the URL length beyond safe lengths. I can't think of a way to use forms and POST to get the variables to the script.

:shock:

I hope that clarifies my bad description of the issue. It's a serious headache.

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Postby ruturajv » Sun Aug 01, 2004 8:14 pm

I think I've got a sol...

Check the session variable on the main page....

and in the img tagl...
<?php
$strvar = "http://somelink/image.php?image1=" . $_SESSION['var1'] . "&image2=" . $_SESSION['var2'];
?>
<img src="<?php echo $strvar?>">

Pass the information to the image.php in the url... !!
I guess that should solve the problem...

George the Flea
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Jul 26, 2004 10:42 pm
Location: Washington
Contact:

Postby George the Flea » Mon Aug 02, 2004 8:53 pm

Pass the information to the image.php in the url... !!
I guess that should solve the problem...


Yeah, that seems to be about all that I can do. Not the best solution, but oh well.

Session and global variables just don't seem to work on pages that are included through an image tag.


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest