Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Reply to Thread

Post a reply to the thread: How to pass variable from page to page with php session?

Your Message

Click here to log in

What is the number after 87?

 
 

You may choose an icon for your message from this list

Additional Options

  • Will turn www.example.com into [URL]http://www.example.com[/URL].

Rate Thread

You may rate this thread from 1-star (Terrible) to 5-stars (Excellent) if you wish to do so.

Topic Review (Newest First)

  • 05-02-2012, 10:12 AM
    Nolanr

    How to pass variable from page to page with php session?

    I have a php script that creates a page when given a new entry and in that page, after the page is made i try to set a variable in the session to be the string of the page name just created like this.
    $_SESSION['newpage'] = $html_file_name;
    when the script is done, it redirects back to the insertion form page with this
    <meta http-equiv="Refresh" content="0; url=http://www.whatever.com/insert.php...
    on that page I had planned to create a link the the page just created like this
    <a href="<?$_SESSION['newpage']?>"> last page created </a>
    also just to let you know, i echoed $_SESSION['newpage'] just before the redirect on the previous page to make sure it got the value of the new page and it did, which is something like "jap-25.php"

    however after the redirect when i try to use this line to make a link to the newly created page...
    <a href="<?$_SESSION['newpage']?>"> last page created </a>
    somehow the $_SESSION['newpage'] has taken the value of the pagename i am using it on. "insert.php" though this $_SESSION['newpage'] is not used ANYWHERE else on that page, and like i said, one line above the redirect on the prev page it was the correct value. I DO have session_start(); on both pages. I dont know how the @$##@ it could have possible gotten this value and its making me pretty POed. I will love you forever if you tell me whats wrong.

    also if it matters, before i was getting blank '' no value on the second page, and without me changing anything it turned to the "insert.php" randomly and is now staying that way.
    tried using the php header to redirect instead, also tried just making an href to click on to get back instead of redirect, no difference.

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •