Page 1 of 1

setting cookie "on self" when reading another webp

Posted: Thu Nov 01, 2007 12:40 pm
by aye
hey everyone,
I have a quite enervating problem here. i am trying to read a webpage, that automatically sets the site language according to the system language. Ie, my host is located in denmark, and hence the whole webpage is in danish. You can however reset the language to whatever language you want on a 'settings' menu, which is using cookies. So, my question being: can you somehow set a cookie on the file reader, making it read the webpage in english instead of the default language?
Help would be very much appreciated!

Posted: Thu Nov 01, 2007 4:45 pm
by s.dot
You will have to have the language files yourself, if that's what you're asking. You'll have to have a language file or similar for each language that you want the site to be in.

Posted: Thu Nov 01, 2007 6:15 pm
by aye
are you sure? the webpage just needs to be read with the cookie value "language=en", and the page will be in english (no need for translating anything). i think i saw a piece of code somewhere that did something similar with fsockopen. don't remember how though.

Posted: Thu Nov 01, 2007 6:33 pm
by s.dot
Yeah, I'm sure.

The cookie could set a value for the site to load the appropriate language file.

e.g.

Code: Select all

if (isset($_COOKIE['lang']) && in_array($_COOKIE['lang'], $allowedLanguages))
{
    require 'lang/' . $_COOKIE['lang'] . '.php';
}
Of course, the rest of your site will need to be able to deal with the constants or variables or whatever defined in lang/en.php (for example).

There's no functions to translate your web site to a different language. You'll have to do it on your own, or perhaps find a third party language translater (if they exist in the manner you wish).

Posted: Sat Nov 03, 2007 6:53 am
by aye
sorry if i didn't explain my problem good enough.
this has nothing to do with my webpage; i'm trying to read (with file i/o) another webpage, which has a cookie-based language system. And, when i'm reading this webpage, i don't want it to be in danish or whatever - i want it to be in english, so that my regex matches don't have to be translated. i'm working on a php based meta-search engine you see :)

Posted: Sat Nov 03, 2007 8:00 am
by onion2k
Send the cookie data with the request for the page. It's a pain to do using fsockopen(), but really easy using Curl http://uk3.php.net/curl .

Posted: Sat Nov 03, 2007 8:45 am
by aye
thanks, ill give it a try

edit: got it to work! thanks a lot, onion2k :D