• adityakumar

    (@adityakumar)


    Hi I want all my new / 1st users to my site to get redirected to a different page.

    Its a wordpress page and in the index.php file I have this code right on top

    <?php
    if ($_COOKIE['iwashere'] != "yes") {
    setcookie("iwashere", "yes", time()+20000);
    header("Location: http://howtobuygoldoffshore.com/sitemap");
    exit;
    }
    ?>

    Now the issue is when I clear all cache and cookies from my browser and access this page it only goes to howtobuygoldoffshore.com instead of going to howtobuygoldoffshore.com/sitemap.

    But now if I access it with a http://www.howtobuygoldoffshore.com then it goes to the correct landing page.(the www. is making some different I suppose)

    What could be the issue? Is the code correct which I am writing and inserting in the index.php file or is there some issue with the re direction?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    You put the code in the WORDPRESS index.php?

    Don’t do that. Put it in your theme. Make a front page template for your theme and put the code there.

    Thread Starter adityakumar

    (@adityakumar)

    Yes I was using the index.php of WordPress. Front page template file? What’s this. Then can’t I use the index.php file of the template? How do you create a front page template file. Since the main index.php files is the one getting created and pulled right in the starting of the sites URL.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    If you no nothing of themes, this is going to be a long, annoying, road.

    POSSIBLY the best place would be to edit your theme and put it in the header.php.

    I strongly suggest making a child theme for this. http://codex.wordpress.org/Child_Themes

    Thread Starter adityakumar

    (@adityakumar)

    But why Wont it work with index.php file? Only with www. It works without that It doesn’t redirect. That means there is some reduction error else the code is working fine.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Editing the WordPress index.php will be overwritten every single time you update WordPress. That is a CORE file it. Stop messing with it, you’re not ready. It’s not a good idea for anyone to edit things like that.

    The proper way to make those changes is with your theme.

    Thread Starter adityakumar

    (@adityakumar)

    Ok. So without making a child these if I simply put that redirect code in the header.php of my theme will it work fine?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Yes.

    But keep in mind, any and all customizations, directly to your theme, will be overwritten when you upgrade the theme.

    Thread Starter adityakumar

    (@adityakumar)

    I can only find index.php in my themes files. No header.php exists in the theme. Its a profits 11 theme

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Go to /wp-content/themes/

    See the folders? Go into the one for you theme.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘PHP redirect based on cookies Issue’ is closed to new replies.