문제

I'm getting that the variable $email is undefined. I know that the emailParser() method works as it does everything it's supposed to do.

How to I make it so that the variable $email persists so that I can access it in the second iteration of index.php?

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $message = $_POST["message"];
    include "etext.php";
    //Run etext

    $email = emailParser($message); //set by running etext


    header("Location: index.php?status=submitted");
    exit;
}

?>

<h1>Etext Email Converter</h1>

<?php
if (isset($_GET["status"]) AND $_GET["status"] == "submitted") {
    $output_file_path = $email->generateParsedEmailFile();

 ?>
    <p> File located at: <?php echo $output_file_path; ?> </p><br>
    <a href=<?php echo $output_file_path;?> >Click Here to Access</a>
<?php
 } else { ?>
    <form method="POST" action="index.php">
        <label for"message"></label>
        <textArea rows="30" cols="40" name="message" id="message"></textArea>
        <input type="submit" value="Submit">

    </form>
<?php } ?>
도움이 되었습니까?

해결책

You can use the $_SESSION super-global to achieve this.

$_SESSION['Email'] = 'example@example.com';

That would make that variable accessible on multiple pages provided you support sessions within your code.

To do that, on every page you want to access the session values you would call

session_start();

and after you have called that, you can go ahead and access the variable you set elsewhere.

echo $_SESSION['Email']; // Outputs example@example.com
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top