SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot santanu's Avatar
    Join Date
    Oct 2003
    Location
    india
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Not getting correct data from URL

    My url is http://localhost/plan-detail.php?planname=CoreGuard EPO 10000 2+ Members&st=CA

    I caprtue get data in php.

    <?
    echo $planName =$_GET['planname'];
    ?>

    OUTPUT >> CoreGuard EPO 10000 2 Members

    1. one space is missing between EPO 10000
    2. '+' is missing

    Output and original value of variable $planname is different. I want to how to solve this problem and why it's happen.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You're not URLencoding the planname value in whatever code creates that URL. It can't include a plus because a plus means a space in a URL. The spaces should be &#37;26.

    Use urlencode().

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If there are such and more complicated special characters that need to be passed through URL then I would normally encode data with MIME base64 and decode it back in the target page.
    PHP Code:
    $url 'http://localhost/plan-detail.php?planname=' base64_encode('CoreGuard EPO 10000 2+ Members') . '&st=CA'
    And in plan-detail.php page
    PHP Code:
    echo base64_decode($_GET['planname']); 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by santanu View Post
    Output and original value of variable $planname is different. I want to how to solve this problem and why it's happen.
    This is a natural issue with the GET method, as spaces are represented in the url as the plus sign.

    If you wish to preserve the spaces and the plus sign for what they are, try use the POST method instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Zealot santanu's Avatar
    Join Date
    Oct 2003
    Location
    india
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everybody for technical support. Using base64_encode i able to solve it.

  6. #6
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You missed the right answer.
    Use urlencode()

  7. #7
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    pnw, there is no single problem with forms. Both GET and POST works fine.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    That's a relief. I have removed that previous post as I as completely wrong.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •