Skip to content
Advertisement

Changing Language in the php and getting id problem

My problem is when I getting in the categories or posts and its specific id’s like this “category.php?category=1 or post.php?p_id=3” and I change the website language when I’m on this page, URL changes to category.php?lang=en or post.php?lang=lt and because of this, I can’t see the post.

What can I do to prevent this?

if(isset($_GET['lang']) && !empty($_GET['lang'])){

    $_SESSION['lang'] = $_GET['lang'];

    if(isset($_SESSION['lang']) && $_SESSION['lang'] != $_GET['lang']){

        echo "<script type='text/javascript'> location.reload(); </script>";

    }

}

if(isset($_SESSION['lang'])){

    include "includes/languages/".$_SESSION['lang'].".php";

} else {

    include "includes/languages/en.php";

} ?>

<form method="get" action="" id="language_form">
                    <div class="input-group">
                        <select name="lang" class="input-control" onchange="changeLanguage()" >
                            <option value="en" <?php if(isset($_SESSION['lang']) && $_SESSION['lang'] == 'en'){ echo "selected"; } ?>>EN</option>

                            <option value="lt" <?php if(isset($_SESSION['lang']) && $_SESSION['lang'] == 'lt'){ echo "selected"; } ?>>LT</option>
                        </select>
                    </div>
</form>

Advertisement

Answer

you have to arrange your url before get request or you can use post so it will not give problem to you.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement