0

I created a session variable in a php page 'session1.php' as follows

<?php
session_start();
$_SESSION['name']="piklu";
?>

now I want to access the session value in another page say 'session2.php'.i need suggestion for that. what I have done in 'session2.php' is as follows.

<?php
include('session1.php');
echo $_SESSION['name'];
?>

The above code is working but only when session1.php and session2.php doesn't contain any html tags.if it is then all html tags from 'session1.php' will be copied to 'session2.php'. Is there any other way to do that?

1 Answer 1

6

You don't need to include all of session1.php. instead, just call session_start() at the start of session2.php.

Sign up to request clarification or add additional context in comments.

1 Comment

's'ok, I'm surprised anyone actually went and uncapsed the question, especially that quickly.

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.