0

I want to create a link inside a php code to redirect to the index.html page, I am able to achieve that with the following line:

echo "<a href='index.html'>Main page</a>";

But I want to execute another php code which simply removes the content of a file before going back to the index page.

I can execute my php code as I did to go to the index, I mean:

    echo "<a href='clear_config.php'>Clear configuration</a>";

But I haven't been able to execute both instructions within a same click (first execute clear_config.php and then go to index.html).

How can I do it?

By using redirection within php code I can get the expected result, but I'm just curious about if it is possible to do it with href tags since clear_config.php is also used in another places where doesn't need to redirect to index.html

8
  • Why don't you take help of JavaScript? Isn't it good idea? Commented Mar 20, 2017 at 10:37
  • <a href='clear_config_and_go_to_page.php?index.html'>Clear configuration and go to the main page</a>? Commented Mar 20, 2017 at 10:38
  • @Jigar7521 Possibly, but I know almost nothing about web-programming and basically I am writing my code by modifying codes I find on the Internet Commented Mar 20, 2017 at 10:39
  • May i can help with JS? Commented Mar 20, 2017 at 10:41
  • 1
    You can also redirect first it to the clear_config.php and then redirect on index.html from that file. Commented Mar 20, 2017 at 10:51

1 Answer 1

1

You can use

header('Location: index.html');

In your clear_config_and_go_to_page.php to redirect to other location.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this works, I also thought about doing the redirection inside the php code, but was curious if it was possible to do it with href tags. If finally there is not another way I will do it like that.
It is not possilbe with same link.If still you want to do that, We have to hit ajax call on onClick method.

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.