Page 1 of 1

The php entrance page opens two times with a link

Posted: Thu Jul 28, 2005 8:00 am
by mustafamisir
Hi,

My web site includes a language option; so, it has a link which changes based on the current language. When, I clicked the link itopens the main page again in the language that I chose. After that, if I click for other languages, it do not open a new page, it only loads the chosen language page in the same page. Therefore, I created a page which directs the real main page. However, it did not work, too.

I am waiting for your help.
Thank you for now.

NOTE: I uses frames.

Posted: Thu Jul 28, 2005 8:27 am
by theda
Now, are you using cookies and conditional statements to pull this all off? (That's what I used to do).

My suggestion:
1. Create three files:
a. index.php file
b. main.php file
c. splash.php file
2. In the splash file, just put the code you want to show up on the splash page when it's loaded. Same with the main.php file.
3. In the index.php file, put something like this (If you use cookies):

Code: Select all

if (isset($HTTP_COOKIE_VARS['language']) AND empty($HTTP_GET_VARS['language'])) {
        $language = $HTTP_COOKIE_VARS['language'];
        include "main.php";
    } elseif (isset($HTTP_GET_VARS['language'])) {
        $language = $HTTP_GET_VARS['language'];
        setcookie('language',$language, time()+60*60*24*30);
        include "main.php";
    } else {
        include "splash.php";
    }
This will check whether "$language" has been set in a cookie, if it has, then it loads that variable, else it saves the current variable (page.php?language=something). Now if a cookie is set, then it loads main.php, if not, it loads splash.php.

Thats pretty much directly out of the code I use for my website. As I have 8 themes and 2 languages you can view my site with/in.

If you want a prettier way of doing the same thing without using conditionals (using switch()'s), then ask, because I do that too ^_^;

Posted: Thu Jul 28, 2005 9:19 am
by timvw
Btw, $HTTP_*_VARS are depreciated. We use $_POST, $_GET, .. now. More at http://www.php.net/variables (predefined variables)

You could use JavaScript to reload _all_ the pages..