1

I'm trying to create an automatic refresh url as below but it doesn't seem to be working.

<?php 
$lastid = 12345
redirect = echo the_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid';
echo '<meta http-equiv="refresh" content="1; url='$redirect'">';
?>

The url I want it to redirect/refresh to would be http://example.com/page-from-options?transid=12345

Any suggestions on what I'm doing wrong?

Jeremy
  • 41
  • 3

4 Answers4

3

You made a several mistakes in your code like

  • You should not use echo like $redirect = echo.
  • You have to use $redirect rather than redirect.
  • No need to use ' after $lastid.
  • And use ; after 12345.
  • edit Concatenate with .. like url='.$redirect.'

Hope this will helps you.

<?php
  $lastid = 12345;
  $redirect = the_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid;
 echo '<meta http-equiv="refresh" content="1; url='.$redirect.'">';
?>
Nirav Joshi
  • 2,924
  • 1
  • 23
  • 45
  • @RïshïKêshKümar Syntax error solved.. lol :D i doesnot run the code i just edited this directly that's why i made mistake.. now i just check the code in localhost and it is working fine now.. Thanx for suggestion :) – Nirav Joshi Jul 03 '17 at 07:57
  • its not work in `localhost` ... or in online fiddle.. get error in `the_permalink` and `get_option` function !! – RïshïKêsh Kümar Jul 03 '17 at 08:02
  • @RïshïKêshKümar have you checked it in wordpress? – Nirav Joshi Jul 03 '17 at 09:35
  • no.. actually its not setup in my local machine .. so !! i just try on the local server and get the the error . now waiting for response from `Jeremy` – RïshïKêsh Kümar Jul 03 '17 at 09:41
1

Solution:

  <?php
    $lastid = 12345;

    $redirect = the_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid;

    echo " <meta http-equiv='refresh' content='1'; url ='<?php $redirect ?>' > ";
  ?>

OR

<?php

     //$redirect = get_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid;
     //$url = "http://example.com/page-from-options?transid=12345";

       $lastid = 12345;

    // Retrieve the `cts_return_page`, and storing it in a variable.
       echo $get_options = get_option('cts_return_page');

    //Displays the URL to the post:
      echo $redirect = the_permalink($get_options).'?transid='.$lastid;


   //echo " <meta http-equiv='refresh' content='1'; url ='http://example.com/<?php $redirect ?>' > ";

?>

<meta http-equiv='refresh' content='1' url='http://example.com/<?php echo $redirect; ?>' >

Problems:

  • First Syntax Error: Semicolon ( ; ) Missing after $lastid = 12345 as Well as You used String Value Here Why ? $lastid its interger value so used like that ex: $lastid = 12345;

  • When You Assign the Value ( = ) then don't use echo , echo is actually used to print the value so avoid to used.

  • -
RïshïKêsh Kümar
  • 4,734
  • 1
  • 24
  • 36
0

You can not set with any variable value with echo statement first you need set variable $redirect value after you can echo $redirect

<?php 
   $lastid = '12345'; // use semicolon
   $redirect = the_permalink(get_option('cts_return_page'))."?transid=".$lastid; // you made mistake here `echo` should not goes here
   echo '<meta http-equiv="refresh" content="1; url="'.$redirect.'">';
?>
Nirav Joshi
  • 2,924
  • 1
  • 23
  • 45
Reena Mori
  • 647
  • 6
  • 15
-1

You're using WordPress, right? I can guess by the the_permalink and get_option functions. If so, the following code should work for you.

More explanation: [edit] See Nirav Joshi's for PHP mistakes you've made. Additionally, as you're using WordPress

  • the_permalink actually echoes the url. You should use get_permalink to store the url in $redirect variable.

Use this code:

    $lastid = 12345;
    $redirect = get_permalink(get_option( 'cts_return_page' )) . '?transid=' . $lastid;
    echo '<meta http-equiv="refresh" content="1; url=' . $redirect . '">';
Junaid
  • 1,270
  • 3
  • 14
  • 33