2011-07-13, 07:09 PM
I'm having some trouble with a bit of PHP. I only added a single line to an otherwise working script and it's suddenly throwing errors at me. There is supposedly an unexpected "}" on line 37 (i've highlighted it)
Any ideas?
Also, sorry for the lack of whitespace, FF doesnt seem to like it XD
Quote:<?php
//require config.php
require("./config.php");
$email = addslashes($_GET['email']);
$cipher = mcrypt_module_open(MCRYPT_3DES, '', 'cbc', '');
$con = mysql_connect($mysql_host.":".$mysql_port,$mysql_username,$mysql_password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($mysql_db, $con);
$result = mysql_query("SELECT * FROM RegistrationInfo WHERE email = '".$email."'");
$row = mysql_fetch_array($result);
//build string
$randomString = (time() + rand(12,24))* rand(3,5);
$xml = "<root><RegistrationInfo><Name>".$row['name']."</Name><Email>".$email."</Email><Key>".$row['key']."</Key><Type>".$row['type']."</Type><ExpiryTimestamp>".$row['expiryTimestamp']."</ExpiryTimestamp><randomString>".$randomString."</randomString></RegistrationInfo></root>";
mysql_close($con);
$xmlString = encrypt($xml);
echo $xmlString;
function Encrypt($buffer) {
global $key, $iv, $cipher;
//make sure the key and IV are the correct lengths
if (strlen($key) < 24) {
$keylength = strlen($key);
$keyfinal = $key;
for ($i = 1; $i <= 24; $i++) {
$keyfinal = $keyfinal.$key;
}
$key = $keyfinal;
$key = substr($key, 0, 24)
}
if (strlen($iv) < 8) {
$ivlength = strlen($iv);
$ivfinal = $iv;
for ($i = 1; $i <= 8; $i++) {
$ivfinal = $ivfinal.$iv;
}
$iv = $ivfinal;
$iv = substr($iv, 0, 8)
}
// get the amount of bytes to pad
$extra = 8 - (strlen($buffer) % 8);
//printvar($extra, 'Padding with n zeros');
// add the zero padding
if($extra > 0) {
for($i = 0; $i < $extra; $i++) {
$buffer .= "\0";
}
}
mcrypt_generic_init($cipher, $key, $iv);
$result = bin2hex(mcrypt_generic($cipher, $buffer));
mcrypt_generic_deinit($cipher);
return $result;
}
function Decrypt($buffer) {
global $key, $iv, $cipher;
//make sure the key and IV are the correct lengths
if (strlen($key) < 24) {
$keylength = strlen($key);
$keyfinal = $key;
for ($i = 1; $i <= 24; $i++) {
$keyfinal = $keyfinal.$key;
}
$key = $keyfinal;
$key = substr($key, 0, 24)
}
if (strlen($iv) < 8) {
$ivlength = strlen($iv);
$ivfinal = $iv;
for ($i = 1; $i <= 8; $i++) {
$ivfinal = $ivfinal.$iv;
}
$iv = $ivfinal;
$iv = substr($iv, 0, 8)
}
mcrypt_generic_init($cipher, $key, $iv);
$result = rtrim(mdecrypt_generic($cipher, hex2bin($buffer)), "\0");
mcrypt_generic_deinit($cipher);
return $result;
}
function hex2bin($data)
{
$len = strlen($data);
return pack("H" . $len, $data);
}
?>
Any ideas?
Also, sorry for the lack of whitespace, FF doesnt seem to like it XD