1

I'm making a page using php and I came to a point where I I have a if with two conditions and I need that if the conditions are true the button sends me to nother page, is that possible?? I have this code right now:

The button:

<form method="post">
    <input type="submit" name="submit" class="buttonStyle" />
</form>

The PHP Script:

<?php
    $homepage = "/site/nelson.php";
    $currentpage = $_SERVER['REQUEST_URI'];
    if(isset($_POST['submit']) && $homepage==$currentpage)
    {
        #Here should be the redirect
    }
?>

Hope someone can help me :) Thanks!

EDIT: found the solution, THANKS(!!!!!!!!!!!!) to all!

Alpha
  • 121
  • 1
  • 3
  • 10

3 Answers3

3

As the other answers suggested you should use the header function. You can also set a delay in the header so it will wait for a couple of seconds before redirecting like this:

    header("Refresh: 5;url=yoururl.com");

If It's not working then you should take a look at this answer!

Community
  • 1
  • 1
Daanvn
  • 1,254
  • 6
  • 27
  • 42
1

header("Location: http://my.domain.com/other_page");

Please note that for this to work, there can be no HTML already be sent to the client. Assuming your code snippet is in the same file, this means the PHP block should be placed before your HTML block.

MarioP
  • 3,752
  • 1
  • 23
  • 32
  • the problem is if I use "header" it gives me a warning because of the meta tags I have... even if I put the php script before the meta tags.. – Alpha Jun 04 '13 at 09:18
  • @user2450939 which meta tags? which warnings? you have to give us details if you want us to help you. – MarioP Jun 04 '13 at 09:41
0
<?php
$homepage = "/site/nelson.php";
$currentpage = $_SERVER['REQUEST_URI'];
if(isset($_POST['submit']) && $homepage==$currentpage)          <--- the php script
{
header('Location: http://www.example.com/');
}
?>

<form method="post">
<input type="submit" name="submit" class="buttonStyle" />     <---the button
</form>
open source guy
  • 2,727
  • 8
  • 38
  • 61