views:

78

answers:

1

Hello,

Currently I am using YOURLS PHP URL shorterning script.

In their functions.php, seems like they support both redirection which is with PHP header location and javascript.

Functions.php

I want to redirect with javascript, which will show me the message before redirect. I found this coding inside functions.php

// Redirect to another page using Javascript. Set optional (bool)$dontwait to false to force manual redirection (make sure a message has been read by user)
function yourls_redirect_javascript( $location, $dontwait = true ) {
    if( $dontwait ) {
    echo <<<REDIR
    <script type="text/javascript">
    window.location="$location";
    </script>
    <small>(if you are not redirected after 10 seconds, please <a href="$location">click here</a>)</small>
REDIR;
    } else {
    echo <<<MANUAL
    <p>Please <a href="$location">click here</a></p>
MANUAL;
    }
}

But I don't know how to do it. Is that coding currently commented or ? What should i change to redirect with javascript ?

Please help me out. Thanks.

+1  A: 

The function is all ready to go. A javascript redirect will occur on the client side, so this script outputs the appropriate javascript. Call it like so:

<?php # http://www.myurl.com/was/here.php

yourls_redirect_javascript('http://www.myurl.com/go/here.php');

?>

When this page loads javascript will be used to redirect the user. If the javascript fails, there will be a link for them to click to follow the redirect.

I suspect that the "here document" syntax is throwing you off a bit. Read the PHP Docs to learn more about echo <<< http://php.net/manual/en/function.echo.php

thetaiko