0

in the root of my project folder i have a file called index.php and a directory called views which contains a file called page_one.php ...

index.php file has the follwing code:

<?php
$action = "one";

if ($action == 'one') {
    $name = "John";
    //include './views/page_one.php';    
    header("Location: views/page_one.php");
}
?>

and page_one.php has the following code:

<?php echo 'Name = ' . $name; ?>

in the above code I have commented out the line with include because that works perfectly..I want to pass the value of $name using the header function..Is there a way of doing it WITHOUT sending the value in the URL?

I want the address in the URL to change when page_one.php is accessed that is why I am using the header function instead of include...

9
  • 4
    You can add it to a session, and then grab it on the next page. Commented Sep 7, 2018 at 19:13
  • if there is a lot of data then wont adding all the data to the SESSION array be inefficient?? Commented Sep 7, 2018 at 19:15
  • @falahmahmood How much is a lot? Commented Sep 7, 2018 at 19:18
  • Inefficient? Doubt it, at least not for anything you'd be doing. By the time it becomes inefficient you will probably understand PHP much better than you do today. You plan on serving thousands of people per second? Commented Sep 7, 2018 at 19:18
  • You just said you wanted to send the $name variable, that doesn't sound like much at all. Commented Sep 7, 2018 at 19:18

1 Answer 1

1

@Qirel as per said, try using session. Do something like this in index.php

<?php
    session_start();
    $_SESSION['name'] = "John";
    header("Location: views/page_one.php);
    exit();
?>

and inside page_one.php

<?php
    session_start();
    echo $_SESSION['name'];
    unset($_SESSION['name']); // remove it now we have used it
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.