1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Getting the url of a website page

Discussion in 'PHP' started by SJappie, Jan 4, 2008.

  1. #1
    The topic title may not be so specific, but it was the best I could come up with.

    Here's the deal. I have a custom made website that get stuff from my database and generates pages out of it. These pages their URLs are created with modrewrite or modwrite, whatever it's called.

    Now I need some way to get the url of a page that a visitor is viewing and make a variable out of it. Why? So that I can put it in Google its translator :)
    Maybe it's clearer with an explanation:

    A visitor is looking at this page, but wants it translated:
    http://www.mydomain.com/bla/nicestory.php

    So therefore I want a link on the page that says:
    http://translate.google.com/translate?u=$the_url_of_the_page&langpair=en%7Cnl&hl=en&ie=UTF8

    So in this example the link on the page would be:
    http://translate.google.com/translate?u=http://www.mydomain.com/bla/nicestory.php&langpair=en%7Cnl&hl=en&ie=UTF8

    Is there some way to do this? Is anybody kind enough to explain this to me? Many many thanks in advance!!
     
    SJappie, Jan 4, 2008 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    try this :

    $_SERVER["PHP_SELF"]

    or

    <?
    $url = $_SERVER['SERVER_NAME'];
    $page = $_SERVER['php_SELF'];
    echo "http://".$url.$page;
    ?>
     
    commandos, Jan 4, 2008 IP
    SJappie likes this.
  3. SJappie

    SJappie Peon

    Messages:
    338
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Commandos for your quick response. Going to give it a try now! :)
    I'm not in any way experienced in PHP, I only know the bare minimum. So I'm hoping for the best ;)
     
    SJappie, Jan 4, 2008 IP
  4. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think this works,

    
    <a href="http://translate.google.com/translate?u=
    <?php
    echo $_SERVER[PHP_SELF];
    ?>
    &langpair=en%7Cnl&hl=en&ie=UTF8">
    Translaste this page
    </a>
    
    Code (markup):
     
    nicangeli, Jan 4, 2008 IP
    SJappie likes this.
  5. SJappie

    SJappie Peon

    Messages:
    338
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Still struggling :p
    Thanks Nicangeli, tried your suggestion too, but didn't work. Tried this -->

    So I tried something else, doing it in pieces. Looking what the 2 different lines would echo.
    Doing this -->

    The first one gives the proper result, it shows the domain. The PHP_SELF however, shows: /index.php
    This is partially correct, cause in fact the real url (before modwrite) is something like: /index.php?showitem=12345 or something. But obviously only /index.php is not correct enough. So how to get the rest? Going on with the research :)
     
    SJappie, Jan 4, 2008 IP
  6. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hello,

    I do Suck with PHP but i just tried the following and it worked, i think :D

    
    <a href="http://translate.google.com/translate?u=
    <?php
    $url = $_SERVER[SERVER_NAME] . $_SERVER[REQUEST_URI];
    echo $url;
    ?>
    &langpair=en%7Cnl&hl=en&ie=UTF-8">
    Translate this page
    </a>
    
    Code (markup):
     
    nicangeli, Jan 4, 2008 IP
  7. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #7
    crazyryan, Jan 4, 2008 IP
    SJappie likes this.
  8. SJappie

    SJappie Peon

    Messages:
    338
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ah I found it!! Cause I use modwrite i need that part of the url after the main domain... That you can do with -->

    <?
    echo $_SERVER['REQUEST_URI']
    ?>

    :) yeah!!

    Oh crazyryan i just see you posted it aswell, thanks for your answer!
    This is the thing I needed. I will post the final version here on the forum as well. Cause I figure there will be more people that could use a thing like this on their website.

     
    SJappie, Jan 4, 2008 IP
  9. SJappie

    SJappie Peon

    Messages:
    338
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #9
    So finally I got it to work the way I wanted. See the results here (top right obviously)
    My thanks goes out to the people that helped me in this thread!
    I saw this thing in a lot of blogs, but I could only find scripts that could be implemented in blogs like from wordpress and such. I could not find any source that offered a way to do this for (custom) websites. I think I have found a way that will work for everyone that has access to the actual files where the script needs to be put in. So if you need it PM me.

    Don't really know if other people need it as well, I could also open a new thread to share it :)

    Thanks again for the input Crazyryan, Nicangeli and Commandos!
     
    SJappie, Jan 4, 2008 IP
    nicangeli likes this.