• Hello,

    I have a page which I have redirected to the home page for a certain group of visitors. I would like a popup welcome message to display only for them once they land on the home page from the redirection.

    I have checked all plugins but they won’t display the message if the page is redirected with a 301. Is there another method?

    Thanks

    Regards

    Tabita Panduro

Viewing 9 replies - 1 through 9 (of 9 total)
  • Is there another method?

    How about creating another page instead of a popup page from where your visitors can click a link and go to your homepage?

    Thread Starter TabyP

    (@tabyp)

    Hi Krishna,
    yeah of course that would be an alternative solution. I just wanted to know if there was a solution for what I wanted aka A popup welcome message displaying on the home page only for visitors coming from another page.

    wpismypuppet

    (@wordpressismypuppet)

    You can’t easily detect 301 redirects… at least it won’t be 100% all of the time. There is an array in PHP called $_SERVER which has an entry called $_SERVER[‘HTTP_REFERER’] which attempts to store the address of the previous page through the user of the user agent string. User agent strings are easily manipulated and can’t be trusted, if they even work at all!

    If you have a page, that you control, that is doing the redirect… why not use PHP to do the redirect itself and pass a variable in the URL that can be detected on page load? If the variable is in the URL, show the pop up. You could even pass the variable hidden so it doesn’t clutter the URL up. This is fool proof as the variable would only exist if the user came from the page doing the redirecting!

    I can offer some examples of code, but I’d need to know your setup to offer significant advice. For example, what group of people are being redirected? How do you determine who is in that group? What happens to those not in that group? Do they stay on the page, or are they redirected elsewhere? And so forth…

    Thread Starter TabyP

    (@tabyp)

    Thanks so much for your help.

    So my group of visitors will be readers of a magazine where I have my ad with this address https://www.clearkidneys.com/men. So only readers will actually type that URL in the browser.
    What happens is that the link gives them an automatic coupon in the cart but when they visit that, the redirect is immediate to https://www.clearkidneys.com (so they don’t even realize basically meaning that they don’t spend any time on /men itself as there is nothing there).
    Once they arrive on the home page, I wanted to display a welcome popup once ONLY FOR THEM saying “Thank you blah blah we will give you discount blah blah”. Then they can close the popup and continue to navigate as normal.
    For visitors who are not coming from /men but from organic or paid search (Google ads, etc.), the coupon is not available so the message is not necessary.

    If you could give me a couple of examples of code of redirect and for the variable, it would be awesome.

    wpismypuppet

    (@wordpressismypuppet)

    An example with a variable in the URL… on the /men page:

    <?php
        header( "Location: somepage.php?myvariable=" . urlencode( "variable value" ) );
    ?>

    and when you get to the page doing the pop up:

    <?php
        if( isset( $_GET['myvariable'] ) ) {
            if( $_GET['myvariable'] == 'variable value' ) {
                // Do something here
            }
        }
    ?>

    It’s good to check the actual value of the variable to make sure no one tampered with it. Make the value weird and unique so it can’t easily be guessed. Also, you can make it random for each time so it can never be guessed… similar to using a nonce. Depending on the situation, a nonce may even be the way to go.

    To do the same thing without a variable in the URL, you’ll need to use a session. On the /men page:

    <?php
        session_start();
        $_SESSION['myvariable'] = "variable value";
        header( "Location: somepage.php" );
    ?>

    and when you get to the page doing the pop up:

    <?php
        session_start();
        if( isset( $_SESSION['myvariable'] ) ) {
            if( $_SESSION['myvariable'] == 'variable value' ) {
                // Do something here
            }
        }
    ?>
    Thread Starter TabyP

    (@tabyp)

    Okay I think I got it up to a certain point.

    So what I would do in the page where my readers will go (www.clearkidneys.com/men) I would put:

    <?php
        session_start();
        $_SESSION['men'] = "variable value" <strong>(what kind of value are we talking about?)</strong>;
        header( "www.clearkidneys.com/men" );
    ?>

    That page will be redirected immediately to my home page (www.clearkidneys.com) with a 301 where I would put:

    <?php
        session_start();
        if( isset( $_SESSION['men'] ) ) {
            if( $_SESSION['men'] == 'variable value' <strong>(I guess a copy of the variable value in the other page)</strong> ) {
                // <strong><em>Do something here</em></strong>
            }
        }
    ?>

    So when it comes to the DO SOMETHING HERE, what type of code should I use exactly to have a popup? I mean I can design the content in HTML obviously but how do I enclose that content in a popup?

    Thanks again, you’re being awesome!

    wpismypuppet

    (@wordpressismypuppet)

    Well, first off you have the first piece a little wrong… you’ll want it to be this:

    <?php
        session_start();
        $_SESSION['men'] = 'yes';
        header( home_url('/') );
    ?>

    For ease of use, let’s just set the ‘men’ variable to “yes”. Once you get it working, you should make it more secure so it’s not easily guessed.

    Also, since you want to send people to the homepage of your WordPress site, we can send them using home_url(). Using this function will allow it to work even if you changed the domain name to something different down the road.

    Your version redirects them back to the /men page, which will cause a continuous loop to happen. Also, because you are using the header() function, you do not need any 301 redirects. That is the point of using this method.

    On the homepage, you have the code correct, but we’ll change the variable to reflect:

    <?php
        session_start();
        if( isset( $_SESSION['men'] ) ) {
            if( $_SESSION['men'] == 'yes' ) {
                // Do something here
            }
        }
    ?>

    As far as the pop up code, you implement something as simple as a JavaScript modal. jQuery is already being used by WordPress as a default, so you could easily use a jQuery modal of some kind. There are literally thousands of scripts out there… just have to find the one that does something similar to what you are looking for. How much programming experience do you have?

    wpismypuppet

    (@wordpressismypuppet)

    Here is a list of 10 popular jQuery popup scripts… if this helps ??

    https://jquerybyexample.blogspot.com/2013/01/jquery-popup-window-tutorial-plugins.html

    Thread Starter TabyP

    (@tabyp)

    As far as Java programming… none! But I have to say that you’re seriously awesome. So as long as I add a java script code for the popup where it says “Do Something here” then it should be okay right? But then, how do I implement in WordPress? For example I like the Java here https://marcosesperon.es/apps/messi/

    Do I add the whole JAVA and HTML in the same PHP coding above? Or do I have to create different files? If so, how do I link them? I mean in normal HTML I know you just use the following in the head:

    <link rel="stylesheet" href="messi.min.css" />
    <script src="messi.js"></script>

    But what about in WordPress?

    Thanks again…

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Redirect page and show popup message’ is closed to new replies.