Sanitizing

Discussion in 'PHP' started by mcfox, Oct 21, 2010.

  1. #1
    What are the best methods for sanitizing?

    For example;

    $_SERVER['HTTP_USER_AGENT']
    $_SERVER['HTTP_ACCEPT']

    I'm thinking xss here but how about also against sql injection?
     
    mcfox, Oct 21, 2010 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    nothing works against sql injections! you just have to check all inputs ($_GET, $_POST, $_FILES, $_COOKIES) before using its data!

    mysql_real_escape_string or use PDO!
     
    EricBruggema, Oct 21, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    Explain what you'd like to do with that? e.g. insert to database? echo/display it? or both?
     
    danx10, Oct 21, 2010 IP
  4. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #4
    Well, those two examples are part of a script to detect mobile browsers

      
    $user_agent       = $_SERVER['HTTP_USER_AGENT'];
    $accept           = $_SERVER['HTTP_ACCEPT'];
    
    PHP:
    The variables are used in the script - e.g.:

    
    case (preg_match('/ipad/i',$user_agent));
    .....
    
    or later if no exact browser agent can be found
    
    
    case ((strpos($accept,'text/vnd.wap.wml')>0)
    
    PHP:
    I want to make sure the input is sanitized (or not vulnerable) so it isn't open to this type of $_SERVER['PHP_SELF'] xss vulnerability, if you know what I mean? (I know it's different but worth checking).

    Nothing gets written to a database - I asked that since I thought it would be helpful for anyone else reading.

    As you may have guessed I'm no coder (I can write it if I have to but it isn't my thing). :eek:
     
    mcfox, Oct 21, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    Don't worry then as its not being displayed to the visitor nor stored - so you have nothing to worry about as the cases are validating it, just leave it as is :)
     
    danx10, Oct 22, 2010 IP
  6. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #6
    Excellent. :)

    Thanks.
     
    mcfox, Oct 23, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    Since I've helped you, perhaps you can help answer my question...I've been on DP for a while and I'd call myself an active member - after reporting a thread aswell as PM'ing numerous staff (mod/admin) (including you) I get no response - would it be that the staff are too busy or simply can't help?

    Thought I'd ask here, seeing as the other methods I've tried (which are encouraged by DP) never worked.
     
    danx10, Oct 23, 2010 IP
  8. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #8
    Ah, that can happen if you PM more than one mod at the same time about the same thing. Everyone thinks everyone else has answered. :)

    The reported post was dealt with. As for the sticky - there already is one.
     
    mcfox, Oct 23, 2010 IP
  9. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #9
    I did'nt PM more then one mod at the same time was more; "Right..your not replying...perhaps I'll PM another...after a few weeks..as I don't want to seem like I'm bombarding you lot!".

    Anyhow I've got the response I wanted - so all sorted.
     
    danx10, Oct 23, 2010 IP
  10. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #10
    Wasn't deliberate I assure you. :)
     
    mcfox, Oct 23, 2010 IP