1

Since I couldn't find the answer to this question anywhere, so here comes the question. But before that, Thanks to anyone who answers/helps in anyway.

The pseudo-code of the index.php page is:

    <html>
            <head><script>
        <?php
        $links = parse_ini_file('links.ini');
        if(isset($_GET['l']) && array_key_exists($_GET['l'], $links)){
        $my_phpvar = $links[$_GET['l']];
        }
        else{
        header('HTTP/1.0 404 Not Found');
        echo 'Unknown link.';
        }
        ?>
        var myjsvar= <?php echo $my_phpvar; ?>
        function go(){
        document.cookie = "visited=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
        window.location.href = "myjsvar";
            }
</script></head>
    <body><a id="myA1" href="javascript:go();" target="_blank">Click</a></body>
            </html>

As is evident, in the above code the myjsvar comes from my_phpvar, and my_phpvar comes from a seperate file links.ini (sorry if I'm boring you, since it's all evident in the code, but I don't wanna miss anything out for anyone who can help)

I have added some rules to the .htaccess file in the root of this directory where index.php is located. The rules that have been added are

RewriteEngine On

RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?l=$1 [L]

The links.ini file looks like this:

ex = https://www.example.com

So the Main Issue is: When I browse the URL http://www.yoursite.com/short/index.php?l=ex , and Click the Button to initiate the function go(), it doesn't take me to the website https://www.example.com

Once again, Thanks to anyone who solves/helps to solve the issue.

0

1 Answer 1

2

Enclose jsvar inside quotes:

var myjsvar = "<?php echo $my_phpvar; ?>";

and later, use it as a variable (and not sring):

window.location.href = myjsvar;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. Didn't look at the basics and my mind was going haywire. Thank you so much once again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.