SRL Archive - General

hmm, using a form to save to a session, then convert to a .png?


Awkwardsaw

2009-08-23 19:53:31

i'm trying to save text in a form to a session, and use the session to convert it to a .png file :) but it doesnt seem to work, and i dont know where its messing up.

this is the form page:
<html>
<form method="POST" action="http://akwardsaw.hostoi.com/createpic.php">
<input type="text" name="text" value="text">
<input type="submit" value="Change">
</form>
</html>
and the link: here

here is the file to convert that text to a .png file:
<?php
$_SESSION['text']=$_POST['text'];
session_start();


header("Content-type: image/png");

function create($text){

$im = imagecreate(100, 30);

$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

imagestring($im, 5, 0, 0, $text, $textcolor);

imagepng($im);
imagedestroy($im);
}

if(isset($_SESSION['text']))
create($_SESSION['text']);
else {
$_SESSION['text']="wat";
create($_SESSION['text']);
}
?>
here

making the pic works, but it doesnt save the POST text from the form into a session :(

nielsie95

2009-08-24 03:34:01

This seems to work for me..


<?php
session_start();
header("Content-type: image/png");

function create($text){

$im = imagecreate(100, 30);

$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

imagestring($im, 5, 0, 0, $text, $textcolor);

imagepng($im);
imagedestroy($im);
}

if(isset($_SESSION['text']))
create($_SESSION['text']);
else {
$_SESSION['text']="wat";
create($_SESSION['text']);
}
?>

I also don't think you can post a form to the session array, it's either POST or GET.

Awkwardsaw

2009-08-24 05:22:20

From: nielsie95
This seems to work for me..


<?php
session_start();
header("Content-type: image/png");

function create($text){

$im = imagecreate(100, 30);

$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

imagestring($im, 5, 0, 0, $text, $textcolor);

imagepng($im);
imagedestroy($im);
}

if(isset($_SESSION['text']))
create($_SESSION['text']);
else {
$_SESSION['text']="wat";
create($_SESSION['text']);
}
?>

I also don't think you can post a form to the session array, it's either POST or GET.


so, to set it, it would be:

$_SESSION['text']=$_POST['text'];?

Awkwardsaw

2009-08-25 02:59:19

sorry for double post, but how would you set the text in the form as a session? thats my next problem =\ i'v tried

$_SESSION['text']=$_POST['text'];

in the form, but meh

nielsie95

2009-08-26 02:54:52

You can do that after you've committed the form with POST. So in your PHP script you add that line and in the form you have method="POST".

Awkwardsaw

2009-09-14 05:17:37

sorry for a semi-grave dig, but when i tried to fix it, it still doesnt save to the session =\

what other ways can i make this work?