setting cookie "on self" when reading another webp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aye
Forum Commoner
Posts: 25
Joined: Wed Apr 11, 2007 9:02 am

setting cookie "on self" when reading another webp

Post 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!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
aye
Forum Commoner
Posts: 25
Joined: Wed Apr 11, 2007 9:02 am

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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).
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
aye
Forum Commoner
Posts: 25
Joined: Wed Apr 11, 2007 9:02 am

Post 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 :)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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 .
aye
Forum Commoner
Posts: 25
Joined: Wed Apr 11, 2007 9:02 am

Post by aye »

thanks, ill give it a try

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