Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect user from php file back to `index.html` on dreamhost

Tags:

redirect

php

I'm setting up a simple landing page on DreamHost. It won't let me put php code in the file index.html. So, when user submits an email address, I use $_POST to submit the email address to another page mail_auto.php.

After seeing a quick "email sent" message, I'd like the user to be directed back to the index.html page from mail_auto.php.

header() looks a bit complex and seems to interfere with the execution of the balance of mail_auto.php.

What's the best way to redirect the user?

like image 221
DBWeinstein Avatar asked Mar 14 '13 14:03

DBWeinstein


People also ask

How do I redirect a PHP page to an HTML page?

Answer: Use the PHP header() Function You can simply use the PHP header() function to redirect a user to a different page. The PHP code in the following example will redirect the user from the page in which it is placed to the URL http://www.example.com/another-page.php .

How do I redirect a URL to index HTML?

To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page.

How do I redirect a PHP file?

To set a permanent PHP redirect, you can use the status code 301. Because this code indicates an indefinite redirection, the browser automatically redirects the user using the old URL to the new page address.


3 Answers

To redirect user back to index.html, use the following:

header('Location: index.html');
exit;

Alternatively, if you want to display something like " Redirecting... " on screen, you can use the meta-refresh method , or JavaScript window.location method with setTimeout

The meta refresh method:

Add this to HTML <head>:

<meta http-equiv="refresh" content="2;url=index.html">

where 2 is number of seconds before the refresh is executed.

like image 83
Raptor Avatar answered Nov 06 '22 01:11

Raptor


Just echo this javascript code end of the process.

    <script>
      window.location.href = 'http://www.yourwebsite.com';
    </script>
like image 25
İlker Korkut Avatar answered Nov 06 '22 02:11

İlker Korkut


Using the header is typically what I'd do.

Have you thought about using JavaScript? It's not the best way, although it would work.

<script type="text/javascript">
   <!--
   window.location = "http://www.google.com/"
   //-->
</script>
like image 24
blamonet Avatar answered Nov 06 '22 03:11

blamonet