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

  • SEARCH
  • Home
  • 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 8980667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:08:41+00:00 2026-06-15T20:08:41+00:00

hello I get crazy through a header-function that does not work. the idea is

  • 0

hello I get crazy through a header-function that does not work.

the idea is that when a user is calling the page foo.php he will be headered. therfor I included a script from script.php

the script reads out the information about the accepted languages from

$_SERVER[“HTTP_ACCEPT_LANGUAGE”])

okay, from that I have the preferred language and a country code that I need to header foo.php into the right language direction. the code from script.php is like:

if ($pref_language == 'af'){
    header('Location:en'.$_SERVER['SCRIPT_NAME']);
    exit;
}
if ($pref_language == 'sq'){
    header('Location:en'.$_SERVER['SCRIPT_NAME']);
    exit;
}

so these examples will header foo.php to directory of

root/en/foo.php

now when calling just script.php that is located in root/scripts/script.php I will headered root/en/scripts/script.php. thats why I would like to add the if-condition that
all if-statements with header(); only take place for files outside of root/scripts/.

so I added:

$filename = $_SERVER['SCRIPT_NAME'];
$path = $_SERVER['HTTP_HOST']."/scripts".$_SERVER['SCRIPT_NAME'];

if (isset($path == false)){

    if ($pref_language == 'af'){
        header('Location:en'.$_SERVER['SCRIPT_NAME']);
        exit;
    }
    if ($pref_language == 'sq'){
        header('Location:en'.$_SERVER['SCRIPT_NAME']);
        exit;
    }
}

that does not work. so if someone could help me out I really would appreciate.

thanks alot.

  • 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-06-15T20:08:42+00:00Added an answer on June 15, 2026 at 8:08 pm

    This can be your solution, although it’s kind of silly in a way, but will do the job:

    <?php
    
    $unwanted_dir = "/scripts";
    
    // this will make sure that the script name doesnt start with "/scripts" 
    if (substr($_SERVER['SCRIPT_NAME'], 0, strlen($unwanted_dir)) != $unwanted_dir){
    
        if ($pref_language == 'af'){
            header('Location:en'.$_SERVER['SCRIPT_NAME']);
            exit;
            }
        if ($pref_language == 'sq'){
            header('Location:en'.$_SERVER['SCRIPT_NAME']);
            exit;
            }
    }
    ?>
    

    another way would be a regular expression, but this is simplier

    I advise you to make it more dynamic on selecting the language. i.e:

    <?php
    
    $unwanted_dir = "/scripts";
    $pref_language == 'af';  // dynamicaly set the language
    $full_path = '/home/php/site/';
    
    // this will make sure that the script name doesnt start with "/scripts" 
    if (substr($_SERVER['SCRIPT_NAME'], 0, strlen($unwanted_dir)) != $unwanted_dir){
    
        if (is_dir($full_path . $pref_language)){
            header('Location:'$full_path . $pref_language . $_SERVER['SCRIPT_NAME']);
        }
        else{
            echo "Sorry, we don't support your language";
            // or
            // header('Location:go/to/unsopported/languages.php');
        }
    
        exit;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I get the following Javascript error when calling goon() within a jquery function.
Hello I get a weird error in this code: function validateForm(aform) { var s=;
Hello I am trying to get the user profile picture and then merge into
I have the following Code var page = '<h1>Hello!</h1><p>FOO</p><span class=username>this is ur name</span><p>sample text</p>';
Hello i get a json that looks like this: features: ( { attributes =
I have a simple test program that when I run I get: ./hello: error
Consider the following snippet: get '/hello/:name' do |n| Hello #{n}! end How can I
I'm trying to get the hello world app running from the doc . I
I'm just starting with Adobe Flex on linux, and can't get the hello world
I got this code in my submit form <form id=myform action='hello.php' method='GET'> <input type=button

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.