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!!
try this : $_SERVER["PHP_SELF"] or <? $url = $_SERVER['SERVER_NAME']; $page = $_SERVER['php_SELF']; echo "http://".$url.$page; ?>
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
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):
Still struggling 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
Hello, I do Suck with PHP but i just tried the following and it worked, i think <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):
$_SERVER['SERVER_NAME'] and $_SERVER['REQUEST_URI'] should be the ones you're after, http://uk2.php.net/reserved.variables
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.
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!