Martney Acha
Martney Acha

Reputation: 3002

Redirect Page in PHP with User Input and new Session

I need to get back to my previous page and display the input of user with display error.

What I did was this

pageone.php
$_SESSION['serial_validation']='validation';
header("location:javascript://history.go(-1)");


page2.php
if(isset($_SESSION["serial_validation"]))
{
echo $_SESSION["serial_validation"];
}

But the redirected page doesnt read the session, any idea on how to prompt this validation ?

Upvotes: 1

Views: 61

Answers (1)

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

Try something like this:

Data processing page:

<?php
session_start();

$_SESSION['errorMSg'] = 'Your message';
// set the error msg in session

$_SESSION['oldValue'] = 'Old value inputted by user';
// Old value inputted by user

header('location:url.php');
// redirect user to specified location

?>

url.php

<?php
session_start();

// check if error msg exist
if(isset($_SESSION['errorMSg']))
{
    echo $_SESSION['errorMSg'];
    // display error message

    echo '<input type="text" value="'. $_SESSION['oldValue'] .'" />';
    // In the same way you can get all old input value and set them
}

?>

Upvotes: 2

Related Questions