---
title: "How to Pass variable to next page in php?"  
description: "How to Pass variable to next page in php?"  
author: "Anonymous User"  
published: 2014-10-30  
updated: 2014-10-30  
canonical: https://www.mindstick.com/forum/2467/how-to-pass-variable-to-next-page-in-php  
category: "php"  
tags: ["php", "session", "session variable"]  
reading_time: 1 minute  

---

# How to Pass variable to next page in php?

it seems pretty [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) but I can't find a good way to do it.\
Say in the first [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) I create a [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation)\
$myVariable = "Some text";\
And the [form](https://www.mindstick.com/forum/6/multi-form-mfc-application)'s [action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) for that page is "Page2.php". So in Page2.php, how can I have [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) to that variable? I know I can do it with [sessions](https://answers.mindstick.com/qa/44945/where-do-i-get-information-on-the-sessions-of-lok-sabha) but I think it's too much for a simple [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp), and I do only need to pass a simple string (a [file name](https://www.mindstick.com/interview/2597/can-you-have-two-files-with-the-same-file-name-in-gac)).

## Replies

### Reply by Anonymous User

HTML / HTTP is stateless, in other words, what you did / saw on the previous page, is completely disconnected with the current page. Except if you use something like sessions, cookies or GET / POST variables. Sessions and cookies are quite easy to use, with session being by far more secure than cookies. More secure, but not completely secure.\
**Session:**\

```
//page 1$_SESSION['varname'] = $var_value;//page 2$var_value = $_SESSION['varname'];
```

\
Remember to run the session_start() statement on both these pages before you try to access the $_SESSION array, and also before any output is sent to the browser.


---

Original Source: https://www.mindstick.com/forum/2467/how-to-pass-variable-to-next-page-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
