SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem displaying url as www

    I am using a little if statment that works great.

    PHP Code:
        if ($webpage == '') {
       
    $hasweb "$teamname";
    } else {
       
    $hasweb "<a href='$webpage'>$teamname</a>";

    the problem is if the user enters http://www.theirsite.com or
    http://theirsite.com
    it prints the desired result but if they enter
    www.theirsite.com it adds my address to the begining of the output
    to resemble this http://www.mysite.com/www.theirsite.com

    What am I doing wrong?

    Thanks
    Steve

  2. #2
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Raleigh, NC
    Posts
    783
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $protocol 'http://';
    if(
    substr($site07) != $protocol)
    $site $protocol $site; } 

  3. #3
    SitePoint Addict loadx's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne, VIC, Australia
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah you must have http:// in the href in some browsers otherwise it thinks its an internal link.

    if the user doesnt have http:// then just append it exactly like darchangel's solution.

  4. #4
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you Darchangel, are the bomb!

    Thank you very much
    Steve

  5. #5
    SitePoint Addict caddyfixr's Avatar
    Join Date
    Aug 2004
    Location
    Albuquerque, NM
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I noticed today that some of my teams had hyper links that didn't before. After a closer look
    I noticed that it was the code that caused the link and it displayed http:/// as the URL.
    So to work around this I modified the code to be like this
    PHP Code:
     $protocol 'http://'
     
     if(
    substr($webpage07) != $protocol
     { 
    $webpage $protocol $webpage; }
      
     if (
    $webpage == 'http://') {
       
    $hasweb "$teamname";
    } else {
       
    $hasweb "<a href='$webpage'>$teamname</a>";

    Now all is wonderful again.
    Thanks
    Steve


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
  •