SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: encoding useragent

  1. #1
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    encoding useragent

    What can be used to encode a user agent to make:

    Mozilla/5.0%20%28Windows;%20U;%20Windows%20NT%205.1;%20en-US;%20rv:1.9.2.13%29%20Gecko/20101203%20Firefox/3.6.13


    Rather than:
    Code:
    $ua = urlencode($_SERVER['HTTP_USER_AGENT']);
    Which gives this format:

    Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.9.2.13%29+Gecko%2F20101203+Firefox%2F3.6.13


    Must a function be written?

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Location
    Internet
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would rawurlencode do what you are after?

    Have you got the original USER AGENT you are using?

  3. #3
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I've come up with this, which seems to at least given a matching string.

    Code:
    $ua2 = "$ua";
    $ua2 = str_replace('%2F', '/', $ua2);
    $ua2 = str_replace('%3B',';',$ua2);
    $ua2 = str_replace('%3A', ':', $ua2);
    $ua2 = str_replace('+' , '%20' , $ua2);
    But the reason I am doing this, is for a SimplePie feed (believe there is no more support there).

    And to my utter amazement, even when the output of a test string exactly matches one that is character entered (which succeeds), the request fails.

    Given what I am faced with, which does not make sense, I don't know if there is anything else I can do with this.

  4. #4
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would rawurlencode do what you are after?
    Comes up with something different.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Location
    Internet
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, have you the original string used for the encode?

  6. #6
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like:


    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13

  7. #7
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry for the double post but the system would not allow an edit, and this may save some time:

    I've recompared and the start and end brackets were omitted, but the request is still not cooperating. Gone over char per char.

    $ua2 = "$ua";
    $ua2 = str_replace('%2F', '/', $ua2);
    $ua2 = str_replace('%3B',';',$ua2);
    $ua2 = str_replace('%3A', ':', $ua2);
    $ua2 = str_replace('+' , '%20' , $ua2);
    $ua2 = str_replace('(' , '%28' , $ua2);
    $ua2 = str_replace(')' , '%29' , $ua2);

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •