Whitespaces Problem in Dynamic URL

Discussion in 'PHP' started by muaazab, Oct 27, 2009.

  1. #1
    echo "<a href=recordsub.php?name=".$_GET['name']."&fname=".$_GET['fname'].">Click Here</a>";

    It works fine when name doesn't have white spaces but if name has white spaces it displays only first part of name and also doesn't show fname.

    Any help?
     
    muaazab, Oct 27, 2009 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    
    echo "<a href=recordsub.php?name=".urlencode($_GET['name'])."&fname=".urlencode($_GET['fname']).">Click Here</a>";
    
    PHP:
    Although I strongly suggest to filter $_GET params to avoid XSS
     
    AsHinE, Oct 27, 2009 IP
  3. dOCnOK

    dOCnOK Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try this

    echo "<a href=\"recordsub.php?name=".$_GET['name']."&fname=".$_GET['fname']."\">Click Here</a>";
     
    dOCnOK, Oct 27, 2009 IP
  4. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I agree with AsHinE
    you need to encode it..
     
    xenon2010, Oct 27, 2009 IP
  5. viron86

    viron86 Active Member

    Messages:
    426
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #5
    write a code that will replace white spaces with + or %20
    i had recently written similar code but it was in j2me

    try str_replace() Function
    eg
     
    viron86, Oct 28, 2009 IP