Reply
???Please read - PHP input using get and securing it.???
Old 06-03-2008, 01:13 AM ???Please read - PHP input using get and securing it.???
goheadtry's Avatar
Webmaster Talker

Posts: 715
Name: John
Location: United States of America, California
Okay I have the following code and I only want it to except text strings no commands etc.
PHP Code:
  $title $_GET['title'];
  
$descr $_GET['descr'];
  
$src $_GET['src']; 
How do I do this?

PHP Code:
<?php
  
  $filepath 
'/home/forbushj/www/vidtemp/';
  
$filetypes = array('video/x-ms-asf''video/x-msvideo''video/x-flv''video/quicktime''video/mp4''video/mpeg''video/x-ms-wmv');
  
$error_msg '';
  
$title $_GET['title'];
  
$descr $_GET['descr'];
  
$src $_GET['src'];
  
// Check for errors:
  
if ($uploaded_size 350000$error_msg .= 'Your file is too large.<br />';
  if (!
in_array($uploaded_type$filetypes)) $error_msg .= 'You may only upload movies.<br />';
  
  if (
$error_msg)
  {
    echo 
$error_msg 'Sorry your file was not uploaded';
  }
  else if (
move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
  {
    
$file $_FILES['uploaded']['tmp_name'];
    
$ext substr($file, ((strrpos($file'.') !== false) ? strrpos($file'.') : strlen($file)), strlen($file));
    
$filename date('Y-m-d-H-i-s') . '_' str_replace(' ''_'basename($file$ext));
    
$filename preg_replace('/[\\\/:*?"<>|]/'''$filename);
    
    if (
is_file($filepath $file))
    {
      
$output = array();
      
      
exec('ffmpeg -i "' escapeshellarg($file) . '" -an -ss 00:00:03 -t 00:00:01 -r 1 -y -s 150x100 -f mjpeg "/home/forbushj/www/pic/video/' escapeshellarg($filename) . '.jpg"'$output$exit_code_pic);
      
exec('ffmpeg -i "' escapeshellarg($file) . '" -ar 22050 -ab 32 -f flv -s 320x240 "/home/forbushj/www/vidd/' escapeshellarg($filename) . '.flv"'$output$exit_code_vid);
      
      if (!
is_array($output)) $error_msg 'Sorry, there was a problem uploading your file.';
      
      if (
$exit_code)
      {
        
error_log('ffmpeg exec returned ' $exit_code);
        
$error_msg 'Sorry, there was a problem uploading your file.';
      }
      
      if (!
$error_msg)
      {
mysql_connect("localhost""REMOVED""REMOVED") or die(mysql_error());
        
mysql_query("
          INSET INTO forbushj_onetest.video (title, descr, pic, locat, src)
          VALUES (
            '" 
mysql_real_escape_string($title) . "',
            '" 
mysql_real_escape_string($descr) . "',
            '" 
mysql_real_escape_string($filename ".jpg") . "',
            '" 
mysql_real_escape_string($filename ".flv") . "',
            '" 
mysql_real_escape_string($src) . "'
          )
        "
);
        echo 
"upload successful";
      }
    }
    else
    {
      
$error_msg 'Sorry, there was a problem uploading your file.';
    }
  }
  else
  {
    
$error_msg 'Sorry, there was a problem uploading your file.';
  }
  
  if (
$error_msg) echo $error_msg;
  
?>
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
When You Register, These Ads Go Away!
     
Old 06-03-2008, 01:17 PM Re: ???Please read - PHP input using get and securing it.???
Average Talker

Posts: 26
Name: Andy
Do you mean something like $title = addslashes($_GET['title']); to stop people putting commands in your form?

Not quite sure what your asking...
Pash is offline
Reply With Quote
View Public Profile
 
Old 06-03-2008, 06:36 PM Re: ???Please read - PHP input using get and securing it.???
goheadtry's Avatar
Webmaster Talker

Posts: 715
Name: John
Location: United States of America, California
Yes, how is it done?
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 06-03-2008, 07:13 PM Re: ???Please read - PHP input using get and securing it.???
Average Talker

Posts: 26
Name: Andy
Like that.

$title = addslashes($_GET['title']);
$descr = addslashes($_GET['descr']);
$src = addslashes($_GET['src']);

It stops anyone using a ' or " to inject code into your script.

It will also escape legitimate 's. So "Jeffery's house" becomes "Jeffery\'s house". Make sure you then use stripslashes($src) when you want to output the data.
Pash is offline
Reply With Quote
View Public Profile
 
Old 06-04-2008, 01:01 AM Re: ???Please read - PHP input using get and securing it.???
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
Actualy, http://us2.php.net/manual/en/functio...ape-string.php will be useful.
Also http://www.webmaster-talk.com/php-fo...injection.html and http://www.webmaster-talk.com/php-fo...s-attacks.html
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Reply     « Reply to ???Please read - PHP input using get and securing it.???
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13378 seconds with 13 queries