Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4346950
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:14:30+00:00 2026-05-21T12:14:30+00:00

First off, please bear with the question as I am just starting out with

  • 0

First off, please bear with the question as I am just starting out with this.

So I have the following running in an index.php:

<?php  

    if(isset($_COOKIE['language'])) {
        if (($_COOKIE['language']) == 'en')
            print "<SCRIPT LANGUAGE=\"JavaScript\">window.location=\"URLGOESHERE\"</SCRIPT>";  
        elseif (($_COOKIE['language']) == 'fr') 
            print "<SCRIPT LANGUAGE=\"JavaScript\">window.location=\"URLGOESHERE\"</SCRIPT>";
    }
    else {
        print "<SCRIPT LANGUAGE=\"JavaScript\">window.location=\"URL-FOR-COOKIE-SETTING-PAGE\"</SCRIPT>";
    }
    ?>

The “else” statement redirect goes to the page where the user sets their language preference, and once they do so, that page sets a cookie then sends them to the proper version of the site. However, when the user goes back to this main index.php, it cannot seem to find the cookie and skips right to the “else” statement. The redirects used to be used done with PHP using ‘header,’ and it didn’t work then either. I had read elsewhere that that could pose some troubles, so I switched it to try printing Javascript.

The weird thing is that I can find the cookie as soon as it is set, exactly where it should be, with the correct name and variable all present. I’ve done it exactly like the books tell me to (to my knowledge). I’ve tried this both in Firefox and Safari with no luck.

What did I miss?

EDIT: Here’s the script that actually sets the cookie. The parameter is sent from the link via a url encode like this: <a href="setlang.php?lang=en">

<?php 

$lang = urlencode($_GET["lang"]);

setcookie("language", $lang, time()+60*60*24*90, ".URL");

switch ($lang) {

case 'en':
header('Location:  URLGOESHERE');
break;

case 'fr':
header('Location:  URLGOESHERE');
break;
}

 ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:14:30+00:00Added an answer on May 21, 2026 at 12:14 pm

    Try this code:

    setcookie("language", $lang, time()+60*60*24*90, "/");
    

    I’m uncertain what .URL was supposed to do o.o

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, this question is ripped out from this question. I did it because
Greetings everyone. This is my first question here at stackoverflow so please bear with
First off, please forgive the stupidness of this question but Im not from a
First off, please do not tl;dr this. It just a lot of quickly-scannable code.
first off I am a rookie so please forgive my basic question. I am
First question here, so please forgive me if this seems obvious. I'm having a
First off, I am using Windows XP. I have multiple hard drives and it
First off, there's a bit of background to this issue available on my blog:
First off, I apologize if this doesn't make sense. I'm new to XHTML, CSS
This problem could be bad class design or ignorance - please bear with me:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.