how to discard image while uploading Apache log file to oracle database

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how to discard image while uploading Apache log file to oracle database



I have designed a script which will upload log file data to oracle database. However i want to filter images in my data upload. Here in this case,i don't want my code to upload CLIENT_REQUEST("GET /icons/back.gif HTTP/1.1") having .gif extensions in my request. Can someone please help me with the code.



My LOG file :-


127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/back.gif HTTP/1.1",304,-,"-"
127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/blank.gif HTTP/1.1",304,-,"-"
127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/unknown.gif HTTP/1.1",304,-,"-"
127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/image2.gif HTTP/1.1",304,-,"-"
127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/text.gif HTTP/1.1",304,-,"-"



My php code


<?php
$conn = oci_connect('XYZ', 'XYZxyz1', 'abcdef1/ABC');
if (!$conn)
$m = oci_error();
echo $m['message'], "n";
exit;

else

$d = new DateTime();
$yesterday = $d->sub(new DateInterval('P1D'))->format('Y.m.d');
$filename = "access.$yesterday.txt";


$myfile = fopen($filename, "r") or die("Unable to open file!");
while(!feof($myfile))
$content= fgets($myfile);
$carray=explode(',',$content);
list($IP_ADDRESS, $USER_IDENTIFIER, $USERID , $REQUEST_TIME , $CLIENT_REQUEST ,$RESPONSE_CODE ,$SIZEOFOBJECT, $COOKIES)=$carray;

$stdii = 'INSERT INTO LOGS(IP_ADDRESS, USER_IDENTIFIER, USERID , REQUEST_TIME , CLIENT_REQUEST ,RESPONSE_CODE ,SIZEOFOBJECT, COOKIES)'.
'values(:IP_ADDRESS, :USER_IDENTIFIER, :USERID , :REQUEST_TIME , :CLIENT_REQUEST ,:RESPONSE_CODE ,:SIZEOFOBJECT, :COOKIES)';
$compiled1 = oci_parse($conn, $stdii);
oci_bind_by_name($compiled1, ':IP_ADDRESS', $IP_ADDRESS);
oci_bind_by_name($compiled1, ':USER_IDENTIFIER', $USER_IDENTIFIER);
oci_bind_by_name($compiled1,':USERID', $USERID);
oci_bind_by_name($compiled1, ':REQUEST_TIME', $REQUEST_TIME);
oci_bind_by_name($compiled1, ':CLIENT_REQUEST', $CLIENT_REQUEST);
oci_bind_by_name($compiled1, ':RESPONSE_CODE', $RESPONSE_CODE);
oci_bind_by_name($compiled1, ':SIZEOFOBJECT', $SIZEOFOBJECT);
oci_bind_by_name($compiled1, ':COOKIES', $COOKIES);
oci_execute($compiled1, OCI_COMMIT_ON_SUCCESS);


echo "File Uploaded";
oci_close($conn);
fclose($myfile);
?>





Possible duplicate of php check file extension in upload form
– Neil Masters
Aug 6 at 8:20





Here in my code i don't want to filter my filename which i want to upload in database. I want to filter my data which i am uploading. In this code i want to put filters on CLIENT_REQUEST so that it doesn't upload .gif or .jpg etc requests. "GET /icons/back.gif HTTP/1.1"
– SSneha
Aug 6 at 9:08





1 Answer
1



If i understand correctly from your comment you want to add everything except images(gif, jpeg, etc) into LOGS table. There is several ways you can achieve this.


LOGS



Do a string length check. This removes the check value from the log and if it does not match the original you have an image.


while()
if (strlen(str_replace(['.gif', '.jpeg'], '', $log)) !== strlen($log))
// Found an image
continue;


// Insert



Or do a regular expression check which searches the log for any matching strings.


while()
if (preg_match("/(.*)(gif



Or iterate an array of banned strings and use strpos to check if the log contains any of the banned strings.


$bannedStrings = ['.gif', '.jpeg'];

while()
foreach ($bannedStrings as $string)
if (strpos($log, $string) !== false)
// Found a banned string
continue;



// Insert



Stackoverflows editor keeps messing up the links to the docs that I am trying to add so giving up.





thanks a lot. It really helped resolving my query.
– SSneha
Aug 7 at 7:14






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard