Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts

    get URL using php

    Hello,

    I'm writing a send to a friend script which sends the URL of a webpage to an email address that the user puts into a form.

    I'm having trouble getting the URL of the page if it is something like articles.php?category=news

    I can handle simple filenames fine like articles.php works no problem.

    PHP Code:
    $dirandfile basename($_SERVER['PHP_SELF']);
    $domain $_SERVER['SERVER_NAME'];
    $url "http://$domain/$dirandfile"
    How can I get my script to handle these url's?

    Thank you,

    Nicola

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    Hi Nicola,

    try the following

    Code:
    $_SERVER['REQUEST_URI']
    the result should be something like
    Code:
    /articles.php?category=news
    Cheers,
    Ess

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    This should do it:

    PHP Code:
    $currentpage $_SERVER['REQUEST_URI'];
    $domain $_SERVER['SERVER_NAME']; 
    $domain str_replace('www.'''$domain); 
    $domain "http://www.$domain";
    $fullurl "$domain$currentpage"
    you can echo currentpage, domain and fullurl seperately to see each result. I believe you are looking for the fullurl.

    Enjoy.
    PHP and MYSQL
    $string = "3Ip*hKEpanKI#8dmUys&*KqlIJ*P8D";
    $new_string = ereg_replace("[^a-z]", "", $string);
    echo "<a href=http://www.$new_string.org>$new_string</a>";

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Thank you!!

    That's great...

    Nicky


  •  

    Posting Permissions

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