Click to See Complete Forum and Search --> : php and base64


spyke01
02-24-2003, 07:38 AM
ok guys trying to make a base64 encoder/decoder this is what i got, but it doesnt work if you can, can you help me put it all in one page?
::base64.php::
<link rel="stylesheet" type="text/css" href="stylesheets/rpg.css">
<body bgcolor=black text=white>
<h3>-==Base 64 Encode==-</h3><hr width=400 align=left>
<form method="post" action="base64run.php">
<textarea name="encode" rows="5" cols="50"></textarea><br>
<input type="submit" name="encodebox" value="Encode" class="dlbutton">
</form>
<P>
<h3>-==Base 64 Dencode==-</h3><hr width=400 align=left>
<form method="post" action="base64run.php">
<textarea name="decode" rows="5" cols="50"></textarea><br>
<input type="submit" name="decodebox" value="Decode" class="dlbutton">
</form>

::base64run.php::
<link rel="stylesheet" type="text/css" href="stylesheets/rpg.css">
<body bgcolor=black text=white>
<h3>-==Base 64 Encode Results==-</h3><hr width=400 align=left>
<? echo base64_encode($encode); ?>
<P>
<h3>-==Base 64 Dencode Results==-</h3><hr width=400 align=left>
<? echo base64_decode($decode); ?>

pyro
02-24-2003, 07:49 AM
You do put it all on one page like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Base 64 Encoder/Decoder</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<link rel="stylesheet" type="text/css" href="stylesheets/rpg.css">
<body bgcolor=black text=white>
<h3>-==Base 64 Encode==-</h3><hr width=400 align=left>
<form method="post" action="spyke01.php">
<textarea name="encode" rows="5" cols="50"></textarea><br>
<input type="submit" name="encodebox" value="Encode" class="dlbutton">
</form>
<P>
<h3>-==Base 64 Dencode==-</h3><hr width=400 align=left>
<form method="post" action="spyke01.php">
<textarea name="decode" rows="5" cols="50"></textarea><br>
<input type="submit" name="decodebox" value="Decode" class="dlbutton">
</form>


<?PHP
if ($encodebox)
{
?>
<h3>-==Base 64 Encode Results==-</h3><hr width=400 align=left>
<?PHP
echo base64_encode($encode);
}
?>
<?PHP
if ($decodebox)
{
?>
<P>
<h3>-==Base 64 Dencode Results==-</h3><hr width=400 align=left>
<?PHP
echo base64_decode($decode);
}
?>
</body>
</html>

spyke01
02-26-2003, 04:07 PM
i get an unrecognized variable for $decodebox and $encodebox

pyro
02-26-2003, 04:21 PM
Perhaps you've changed some names around and that is why. Those variables are returning the items in bold

<form method="post" action="spyke01.php">
<textarea name="encode" rows="5" cols="50"></textarea><br>
<input type="submit" name="encodebox" value="Encode" class="dlbutton">
</form>
<P>
<h3>-==Base 64 Dencode==-</h3><hr width=400 align=left>
<form method="post" action="spyke01.php">
<textarea name="decode" rows="5" cols="50"></textarea><br>
<input type="submit" name="decodebox" value="Decode" class="dlbutton">
</form>

spyke01
03-01-2003, 09:51 AM
what about action=spyke01.php can i change this?

pyro
03-01-2003, 10:47 AM
The action needs to point to this:

<?PHP
if ($encodebox)
{
?>
<h3>-==Base 64 Encode Results==-</h3><hr width=400 align=left>
<?PHP
echo base64_encode($encode);
}
?>
<?PHP
if ($decodebox)
{
?>
<P>
<h3>-==Base 64 Dencode Results==-</h3><hr width=400 align=left>
<?PHP
echo base64_decode($decode);
}
?>So, if you put that in a file called base64.php, your action needs to be action="base64.php" Also, if you put the above code in a new file, you can remove the if($...)'s