1

I am not an expert in php and I want to do the following.

I have three views index, step1 and step2

In index view I have an input for a website link, I also have a function which grab some data (name, price, details) from the website and display it on step1. Here I have some other inputs, but I want to post name, price and details in my session so I can get them to step2 without using any inputs.

I tried $name = $_SESSION['name']; and on step2 I tried to display it

 echo $_SESSION['step1']['name'];

But I think this isn't the solution. I hope I made my self clear.

tereško
  • 58,060
  • 25
  • 98
  • 150
Adrian George
  • 171
  • 1
  • 11
  • 1
    You already have an answer below. Now, in order for it to work properly, remember to have `session_start();` at the top of every file used, right underneath your opening PHP tag `` – Funk Forty Niner Aug 25 '13 at 23:23
  • Thanks @Fred-ii-, forgot that part in the hurry. – OptimusCrime Aug 25 '13 at 23:23
  • I am using a MVC and session is instantiated when a user logs into the application. But i am not such an expert and I am stuck at this point. – Adrian George Aug 25 '13 at 23:24
  • @AdrianGeorge Ok, I added relevant tag to your question. – Funk Forty Niner Aug 25 '13 at 23:26
  • 1
    @AdrianGeorge Try Googling "pass session name from post variable php" and you will see a lot of different results, many of which leading back here to SO. [**Google search link**](https://www.google.ca/search?q=mvc&ie=utf-8&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&channel=np&source=hp&gws_rd=cr#channel=np&fp=2928f75885f71dc4&q=pass+session+name+from+post+variable+php&rls=org.mozilla:en-US%3Aofficial&safe=off) – Funk Forty Niner Aug 25 '13 at 23:31
  • @AdrianGeorge And [**this one**](http://stackoverflow.com/questions/16013033/how-do-i-create-and-pass-post-variable-in-session-array-to-another-page) in particular seems to fit the bill. See the accepted answer on that page. – Funk Forty Niner Aug 25 '13 at 23:35
  • @Fred-ii- There's no accepted answer on that page – Yang Aug 26 '13 at 00:25
  • @DaveJust Sorry Dave, my mistake. I must've looked at another page and put the wrong link. However, I would think that the answer that was given, would be good. – Funk Forty Niner Aug 26 '13 at 00:29

1 Answers1

0

Store value from $name to $_SESSION['name']:

$_SESSION['name'] = $name;

Echoing content of the session-variable:

echo $_SESSION['name'];

Easy as that!

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96
  • I didn't know why I was trying to echo the content of the session variable like echo $_SESSION['step1']['name']; . I was supposed to use this only if I would have posted it from a form input, right? – Adrian George Aug 25 '13 at 23:27
  • @AdrianGeorge Well, I guess it's like he said: *"Easy as that!"* Glad it worked out! – Funk Forty Niner Aug 25 '13 at 23:44