<?php
function GetASPSessionState(){
if(stripos($_SERVER["HTTP_COOKIE"], "ASPSESSIONID") === false){
# since ASP sessions stored in memory
# don't make request to get ASP session state if the cookie does not contain ASPSESSIONID
# otherwise IIS will create new redundant sessions for each of your checks so it wouldn't be a memory-friendly way
# returning an empty array
return array();
} else {
$username = "";
$password = "";
$options = array('http' =>
array('method'=>"GET", 'header' => array("Cookie: " . $_SERVER["HTTP_COOKIE"],
"Authorization: Basic " . base64_encode("$username:$password"))
)
);
$protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
$cx = stream_context_create($options);
$response = file_get_contents($protocol.$_SERVER['HTTP_HOST'] . "/php/sessionConnector.asp", false, $cx);
$data = json_decode($response, TRUE);
return json_decode($response, JSON_FORCE_OBJECT);
}
}
$aspSessionState = GetASPSessionState();
if (trim($aspSessionState["Staff"]) !== "Yes"){
header("Location: /admin/login.asp");
}
require_once "../DbConnection.php";
function Is_a_Number($inputbox) {
$teststring = Trim($inputbox);
if ($teststring == "") {
return False;
}
$i = 0;
while ($i <= strlen($teststring) - 1) {
$c = substr($teststring,$i,1);
if ($c <> "0" & $c <> "1" & $c <> "2" & $c <> "3" & $c <> "4" & $c <> "5" & $c <> "6" & $c <> "7" & $c <> "8" & $c <> "9") {
return False;
}
$i = $i + 1;
}
return True;
}
if (isset($_POST["BlogCategoryID"])) {
$BlogCategoryID = trim($_POST["BlogCategoryID"]);
}
else {
$BlogCategoryID = 0;
}
$BlogID = trim($_POST["BlogID"]);
$BlogMasterCategoryID = trim($_POST["BlogMasterCategoryID"]);
$CreatedBy = trim($aspSessionState["LoginName"]);
$Status = trim($_POST["Status"]);
$BlogTitle = trim($_POST["BlogTitle"]);
$MetaTitle = "";
if (isset($_POST["MetaTitle"])) {
$MetaTitle = trim($_POST["MetaTitle"]);
}
$MetaKeywords = "";
if (isset($_POST["MetaKeywords"])) {
$MetaKeywords = trim($_POST["MetaKeywords"]);
}
$MetaDescription = "";
if (isset($_POST["MetaDescription"])) {
$MetaDescription = trim($_POST["MetaDescription"]);
}
$Introduction = "";
if (isset($_POST["Introduction"])) {
$Introduction = trim($_POST["Introduction"]);
}
$BlogContent = "";
if (isset($_POST["BlogContent"])) {
$BlogContent = trim($_POST["BlogContent"]);
}
$YouTubeEmbedCode = "";
if (isset($_POST["YouTubeEmbedCode"])) {
$YouTubeEmbedCode = trim($_POST["YouTubeEmbedCode"]);
}
$SoundCloudEmbedCode= "";
if (isset($_POST["SoundCloudEmbedCode"])) {
$SoundCloudEmbedCode = trim($_POST["SoundCloudEmbedCode"]);
}
$ButtonEmbedCode = "";
if (isset($_POST["ButtonEmbedCode"])) {
$ButtonEmbedCode = trim($_POST["ButtonEmbedCode"]);
}
$ImageFileName1 = "";
$ImageFileName2 = "";
$ImageFileName3 = "";
$ImageFileName4 = "";
$ImageFileName5 = "";
if (Is_a_Number(trim($_POST["BlogMasterCategoryID"])) & trim($_POST["Status"]) !== "" & trim($_POST["BlogTitle"]) !== "" & trim($_POST["BlogMasterCategoryName"]) !== "") {
if (!Is_a_Number(trim($_POST["BlogID"]))) {
if (isset($_FILES['ImageFile1']["size"])) {
if (trim($_FILES['ImageFile1']["size"]) > 0) {
$FileSize1 = trim($_FILES['ImageFile1']["size"]);
if (trim($FileSize1) > 500000) {
echo("The first file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName1 = trim($_FILES['ImageFile1']['name']);
$File_Type1 = trim($_FILES['ImageFile1']["type"]);
$File_Tmp1 = $_FILES['ImageFile1']['tmp_name'];
$fp = fopen($File_Tmp1, 'rb');
$ImageFile1 = fread($fp, filesize($File_Tmp1));
}
}
if (isset($_POST["RemoveImage1"])) {
if (trim($_POST["RemoveImage1"]) == "Y") {
$ImageFile1 = NULL;
$ImageFileName1 = NULL;
}
}
if (isset($_FILES['ImageFile2']["size"])) {
if (trim($_FILES['ImageFile2']["size"]) > 0) {
$FileSize2 = trim($_FILES['ImageFile2']["size"]);
if (trim($FileSize2) > 500000) {
echo("The second file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName2 = trim($_FILES['ImageFile2']['name']);
$File_Type2 = trim($_FILES['ImageFile2']["type"]);
$File_Tmp2 = $_FILES['ImageFile2']['tmp_name'];
$fp = fopen($File_Tmp2, 'rb');
$ImageFile2 = fread($fp, filesize($File_Tmp2));
}
}
if (isset($_POST["RemoveImage2"])) {
if (trim($_POST["RemoveImage2"]) == "Y") {
$ImageFile2 = NULL;
$ImageFileName2 = NULL;
}
}
if (isset($_FILES['ImageFile3']["size"])) {
if (trim($_FILES['ImageFile3']["size"]) > 0) {
$FileSize3 = trim($_FILES['ImageFile3']["size"]);
if (trim($FileSize3) > 500000) {
echo("The third file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName3 = trim($_FILES['ImageFile3']['name']);
$File_Type3 = trim($_FILES['ImageFile3']["type"]);
$File_Tmp3 = $_FILES['ImageFile3']['tmp_name'];
$fp = fopen($File_Tmp3, 'rb');
$ImageFile3 = fread($fp, filesize($File_Tmp3));
}
}
if (isset($_POST["RemoveImage3"])) {
if (trim($_POST["RemoveImage3"]) == "Y") {
$ImageFile3 = NULL;
$ImageFileName3 = NULL;
}
}
if (isset($_FILES['ImageFile4']["size"])) {
if (trim($_FILES['ImageFile4']["size"]) > 0) {
$FileSize4 = trim($_FILES['ImageFile4']["size"]);
if (trim($FileSize4) > 500000) {
echo("The fourth file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName4 = trim($_FILES['ImageFile4']['name']);
$File_Type4 = trim($_FILES['ImageFile4']["type"]);
$File_Tmp4 = $_FILES['ImageFile4']['tmp_name'];
$fp = fopen($File_Tmp4, 'rb');
$ImageFile4 = fread($fp, filesize($File_Tmp4));
}
}
if (isset($_POST["RemoveImage4"])) {
if (trim($_POST["RemoveImage4"]) == "Y") {
$ImageFile4 = NULL;
$ImageFileName4 = NULL;
}
}
if (isset($_FILES['ImageFile5']["size"])) {
if (trim($_FILES['ImageFile5']["size"]) > 0) {
$FileSize5 = trim($_FILES['ImageFile5']["size"]);
if (trim($FileSize5) > 500000) {
echo("The fifth file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName5 = trim($_FILES['ImageFile5']['name']);
$File_Type5 = trim($_FILES['ImageFile5']["type"]);
$File_Tmp5 = $_FILES['ImageFile5']['tmp_name'];
$fp = fopen($File_Tmp5, 'rb');
$ImageFile5 = fread($fp, filesize($File_Tmp5));
}
}
if (isset($_POST["RemoveImage5"])) {
if (trim($_POST["RemoveImage5"]) == "Y") {
$ImageFile5 = NULL;
$ImageFileName5 = NULL;
}
}
$sql = "SELECT Count(BlogID) as RecCount FROM Blog where BlogCategoryID = " . trim($BlogCategoryID) . " and BlogMasterCategoryID = " . trim(trim($BlogMasterCategoryID)) . " and CreatedBy = '" . str_replace("'", "''",trim($CreatedBy)) . "' and Status = '" . str_replace("'", "''",trim($Status)) . "' and BlogTitle = '" . str_replace("'", "''",trim($BlogTitle)) . "' and MetaTitle = '" . str_replace("'", "''",trim($MetaTitle)). "' and MetaKeywords = '" . str_replace("'", "''",trim($MetaKeywords)) . "' and MetaDescription= '" . str_replace("'", "''",trim($MetaDescription)) . "' and Introduction = '" . str_replace("'", "''",trim($Introduction)) . "' and BlogContent = '" . str_replace("'", "''",trim($BlogContent)) . "' and YouTubeEmbedCode = '" . str_replace("'", "''",trim($YouTubeEmbedCode)) . "' and SoundCloudEmbedCode = '" . str_replace("'", "''",trim($SoundCloudEmbedCode)) . "' and ButtonEmbedCode = '" . str_replace("'", "''",trim($ButtonEmbedCode)) . "'";
$stmt = sqlsrv_query( $connect, $sql );
if ( $stmt === false) {
die( print_r( sqlsrv_errors(), true));
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
$RecCount = $row['RecCount'];
}
if (trim($RecCount) == 0) {
$params = array(trim($BlogCategoryID), trim($BlogMasterCategoryID), trim($CreatedBy), trim($Status), trim($BlogTitle), trim($MetaTitle), trim($MetaKeywords), trim($MetaDescription), trim($Introduction), trim($BlogContent), trim($YouTubeEmbedCode), trim($SoundCloudEmbedCode), trim($ButtonEmbedCode));
$SQLStart = "INSERT INTO Blog (BlogCategoryID, BlogMasterCategoryID, CreatedBy, Status, BlogTitle, MetaTitle, MetaKeywords, MetaDescription, Introduction, BlogContent, YouTubeEmbedCode, SoundCloudEmbedCode, ButtonEmbedCode";
$SQLMiddle = " values(CONVERT(int,?),CONVERT(int,?),?,?,?,?,?,?,?,?,?,?,?";
$SQLEnd = ")";
if (trim($ImageFileName1) <> "" | is_null($ImageFileName1)) {
$params[] = trim(trim($ImageFile1));
$params[] = trim($ImageFileName1);
$SQLEnd = ",CONVERT(VARBINARY(max),?),?" . $SQLEnd;
$SQLStart = $SQLStart . ", ImageFile1, ImageFileName1";
}
if (trim($ImageFileName2) <> "" | is_null($ImageFileName2)) {
$params[] = trim(trim($ImageFile2));
$params[] = trim($ImageFileName2);
$SQLEnd = ",CONVERT(VARBINARY(max),?),?" . $SQLEnd;
$SQLStart = $SQLStart . ", ImageFile2, ImageFileName2";
}
if (trim($ImageFileName3) <> "" | is_null($ImageFileName3)) {
$params[] = trim(trim($ImageFile3));
$params[] = trim($ImageFileName3);
$SQLEnd = ",CONVERT(VARBINARY(max),?),?" . $SQLEnd;
$SQLStart = $SQLStart . ", ImageFile3, ImageFileName3";
}
if (trim($ImageFileName4) <> "" | is_null($ImageFileName4)) {
$params[] = trim(trim($ImageFile4));
$params[] = trim($ImageFileName4);
$SQLEnd = ",CONVERT(VARBINARY(max),?),?" . $SQLEnd;
$SQLStart = $SQLStart . ", ImageFile4, ImageFileName4";
}
if (trim($ImageFileName5) <> "" | is_null($ImageFileName5)) {
$params[] = trim(trim($ImageFile5));
$params[] = trim($ImageFileName5);
$SQLEnd = ",CONVERT(VARBINARY(max),?),?" . $SQLEnd;
$SQLStart = $SQLStart . ", ImageFile5, ImageFileName5";
}
$SQL = $SQLStart . ")" . $SQLMiddle . $SQLEnd;
$stmt = sqlsrv_query( $connect, $SQL, $params);
if ( $stmt === false) {
die( print_r( sqlsrv_errors(), true));
}
header("Location: /admin/posts/default.asp");
}
header("Location: /admin/posts/default.asp");
}
else {
if (isset($_FILES['ImageFile1']["size"])) {
if (trim($_FILES['ImageFile1']["size"]) > 0 | is_null($ImageFileName1)) {
$FileSize1 = trim($_FILES['ImageFile1']["size"]);
if (trim($FileSize1) > 500000) {
echo("The first file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName1 = trim($_FILES['ImageFile1']['name']);
$File_Type1 = trim($_FILES['ImageFile1']["type"]);
$File_Tmp1 = $_FILES['ImageFile1']['tmp_name'];
$fp = fopen($File_Tmp1, 'rb');
$ImageFile1 = fread($fp, filesize($File_Tmp1));
}
}
if (isset($_POST["RemoveImage1"])) {
if (trim($_POST["RemoveImage1"]) == "Y") {
$ImageFile1 = NULL;
$ImageFileName1 = NULL;
}
}
if (isset($_FILES['ImageFile2']["size"]) | is_null($ImageFileName2)) {
if (trim($_FILES['ImageFile2']["size"]) > 0) {
$FileSize2 = trim($_FILES['ImageFile2']["size"]);
if (trim($FileSize2) > 500000) {
echo("The second file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName2 = trim($_FILES['ImageFile2']['name']);
$File_Type2 = trim($_FILES['ImageFile2']["type"]);
$File_Tmp2 = $_FILES['ImageFile2']['tmp_name'];
$fp = fopen($File_Tmp2, 'rb');
$ImageFile2 = fread($fp, filesize($File_Tmp2));
}
}
if (isset($_POST["RemoveImage2"])) {
if (trim($_POST["RemoveImage2"]) == "Y") {
$ImageFile2 = NULL;
$ImageFileName2 = NULL;
}
}
if (isset($_FILES['ImageFile3']["size"]) | is_null($ImageFileName3)) {
if (trim($_FILES['ImageFile3']["size"]) > 0) {
$FileSize3 = trim($_FILES['ImageFile3']["size"]);
if (trim($FileSize3) > 500000) {
echo("The third file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName3 = trim($_FILES['ImageFile3']['name']);
$File_Type3 = trim($_FILES['ImageFile3']["type"]);
$File_Tmp3 = $_FILES['ImageFile3']['tmp_name'];
$fp = fopen($File_Tmp3, 'rb');
$ImageFile3 = fread($fp, filesize($File_Tmp3));
}
}
if (isset($_POST["RemoveImage3"])) {
if (trim($_POST["RemoveImage3"]) == "Y") {
$ImageFile3 = NULL;
$ImageFileName3 = NULL;
}
}
if (isset($_FILES['ImageFile4']["size"]) | is_null($ImageFileName4)) {
if (trim($_FILES['ImageFile4']["size"]) > 0) {
$FileSize4 = trim($_FILES['ImageFile4']["size"]);
if (trim($FileSize4) > 500000) {
echo("The fourth file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName4 = trim($_FILES['ImageFile4']['name']);
$File_Type4 = trim($_FILES['ImageFile4']["type"]);
$File_Tmp4 = $_FILES['ImageFile4']['tmp_name'];
$fp = fopen($File_Tmp4, 'rb');
$ImageFile4 = fread($fp, filesize($File_Tmp4));
}
}
if (isset($_POST["RemoveImage4"])) {
if (trim($_POST["RemoveImage4"]) == "Y") {
$ImageFile4 = NULL;
$ImageFileName4 = NULL;
}
}
if (isset($_FILES['ImageFile5']["size"]) | is_null($ImageFileName5)) {
if (trim($_FILES['ImageFile5']["size"]) > 0) {
$FileSize5 = trim($_FILES['ImageFile5']["size"]);
if (trim($FileSize5) > 500000) {
echo("The fifth file you supplied is too large to process. Please use your browser's Back button and select a smaller file.");
die();
}
$ImageFileName5 = trim($_FILES['ImageFile5']['name']);
$File_Type5 = trim($_FILES['ImageFile5']["type"]);
$File_Tmp5 = $_FILES['ImageFile5']['tmp_name'];
$fp = fopen($File_Tmp5, 'rb');
$ImageFile5 = fread($fp, filesize($File_Tmp5));
}
}
if (isset($_POST["RemoveImage5"])) {
if (trim($_POST["RemoveImage5"]) == "Y") {
$ImageFile5 = NULL;
$ImageFileName5 = NULL;
}
}
$params = array(trim($BlogCategoryID), trim($BlogMasterCategoryID), trim($CreatedBy), trim($Status), trim($BlogTitle), trim($MetaTitle), trim($MetaKeywords), trim($MetaDescription), trim($Introduction), trim($BlogContent), trim($YouTubeEmbedCode), trim($SoundCloudEmbedCode), trim($ButtonEmbedCode));
$SQLStart = "update Blog set BlogCategoryID = CONVERT(int,?), BlogMasterCategoryID = CONVERT(int,?), CreatedBy = ? , Status = ? , BlogTitle = ? , MetaTitle = ? , MetaKeywords = ? , MetaDescription = ? , Introduction = ? , BlogContent = ? , YouTubeEmbedCode = ? , SoundCloudEmbedCode = ? , ButtonEmbedCode = ?";
$SQLEnd = " where BlogID=CONVERT(int,?)";
if (trim($ImageFileName1) <> "" | is_null($ImageFileName1)) {
$params[] = trim(trim($ImageFile1));
$params[] = trim($ImageFileName1);
$SQLStart = $SQLStart . ", ImageFile1 = CONVERT(VARBINARY(max),?) , ImageFileName1 = ?";
}
if (trim($ImageFileName2) <> "" | is_null($ImageFileName2)) {
$params[] = trim(trim($ImageFile2));
$params[] = trim($ImageFileName2);
$SQLStart = $SQLStart . ", ImageFile2 = CONVERT(VARBINARY(max),?) , ImageFileName2 = ?";
}
if (trim($ImageFileName3) <> "" | is_null($ImageFileName3)) {
$params[] = trim(trim($ImageFile3));
$params[] = trim($ImageFileName3);
$SQLStart = $SQLStart . ", ImageFile3 = CONVERT(VARBINARY(max),?) , ImageFileName3 = ?";
}
if (trim($ImageFileName4) <> "" | is_null($ImageFileName4)) {
$params[] = trim(trim($ImageFile4));
$params[] = trim($ImageFileName4);
$SQLStart = $SQLStart . ", ImageFile4 = CONVERT(VARBINARY(max),?) , ImageFileName4 = ?";
}
if (trim($ImageFileName5) <> "" | is_null($ImageFileName5)) {
$params[] = trim(trim($ImageFile5));
$params[] = trim($ImageFileName5);
$SQLStart = $SQLStart . ", ImageFile5 = CONVERT(VARBINARY(max),?) , ImageFileName5 = ?";
}
$params[] = trim($BlogID);
$SQL = $SQLStart . $SQLEnd;
$stmt = sqlsrv_query( $connect, $SQL, $params);
if ( $stmt === false) {
die( print_r( sqlsrv_errors(), true));
}
header("Location: /admin/posts/default.asp");
}
}
header("Location: /admin/posts/default.asp");
?>
Glad I am not the only one who is puzzled. At least two other sites work. I have removed the username and password by the way. The form is a classic asp page that posts to this one. Classic asp is not my idea. Will changing the encoding on this page sort it out and if so to what? Thanks