$_SESSION vs. $variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ken

    $_SESSION vs. $variable

    What am I doing wrong?

    I set the variable co_name on the first page with an <input.... > and
    session_start() at the top of both pages.

    Clicking on a link that takes me to the second page:

    Script on the second page.

    echo $_SESSION['co_name']; Does not display
    value of co_name
    echo "Variable name co_name = ".$co_name; Displays value of co_name

    One book suggested using echo {$_SESSION['co_name']}; Does not run.

    Server is Apache2 Triad

    Any suggestions. I would like to use $_SESSION incase I move to another
    server without ??register_glob als?? ON

    Thanks for the help.


  • Andreas Paasch

    #2
    Re: $_SESSION vs. $variable

    Ken wrote:
    [color=blue]
    > What am I doing wrong?
    >
    > I set the variable co_name on the first page with an <input.... > and
    > session_start() at the top of both pages.
    >
    > Clicking on a link that takes me to the second page:
    >
    > Script on the second page.
    >
    > echo $_SESSION['co_name']; Does not display
    > value of co_name
    > echo "Variable name co_name = ".$co_name; Displays value of co_name
    >
    > One book suggested using echo {$_SESSION['co_name']}; Does not run.
    >
    > Server is Apache2 Triad
    >
    > Any suggestions. I would like to use $_SESSION incase I move to another
    > server without ??register_glob als?? ON
    >
    > Thanks for the help.[/color]

    You have considered the manual at php.net ?
    Especially about session_registe r("co_name") prior to $_SESSION["co_name"] =
    "something" on the first page ?

    Or rather, in your case a minor rewrite according to the input statement ?

    /Andreas
    --
    Peace and long life ...
    Registeret Linux user #292411

    Comment

    • Pedro Graca

      #3
      Re: $_SESSION vs. $variable

      Ken wrote:[color=blue]
      > What am I doing wrong?
      >
      > I set the variable co_name on the first page with an <input.... > and
      > session_start() at the top of both pages.[/color]

      How are you putting co_name into the session variable on the first page?
      [color=blue]
      > Clicking on a link that takes me to the second page:
      >
      > Script on the second page.
      >
      > echo $_SESSION['co_name'];[/color]

      The PHP manual for session_registe r()
      ( @ http://www.php.net/session_register )
      has a word of caution against using session_registe r() and $_SESSION
      together.
      --
      --= my mail box only accepts =--
      --= Content-Type: text/plain =--
      --= Size below 10001 bytes =--

      Comment

      • Andreas Paasch

        #4
        Re: $_SESSION vs. $variable

        Ken wrote:
        [color=blue]
        > What am I doing wrong?
        >
        > I set the variable co_name on the first page with an <input.... > and
        > session_start() at the top of both pages.
        >
        > Clicking on a link that takes me to the second page:
        >
        > Script on the second page.
        >
        > echo $_SESSION['co_name']; Does not display
        > value of co_name
        > echo "Variable name co_name = ".$co_name; Displays value of co_name
        >
        > One book suggested using echo {$_SESSION['co_name']}; Does not run.
        >
        > Server is Apache2 Triad
        >
        > Any suggestions. I would like to use $_SESSION incase I move to another
        > server without ??register_glob als?? ON
        >
        > Thanks for the help.[/color]

        Now thinking of it a bit further - please do disregard my other post.
        What you want is not sessions, but a way to read form input on another page.

        If the form is of method=POST, on the page that is called then you can read
        each variable by $_POST["fieldname"], if it's a method=GET of course using
        $_GET["fieldname"] or alternatively, $_REQUEST["fieldname"].

        Sessions, is a totally different subject.
        And you were referring to register_global s, so this is what you wanted and
        this doesn't need a session_start() at each page in order to work.

        /Andreas
        --
        Peace and long life ...
        Registeret Linux user #292411

        Comment

        • Ken

          #5
          Re: $_SESSION vs. $variable

          I want to carry variables from the input page through to 2 or 3 other pages;
          then save the variables in a table or array for future downloading.

          There can be several user transferring data at the same time.

          What is the best way to do that?

          I thought sessions would keep the data from being intermingled between
          users.

          What is the operational difference between

          $_SESSION['variable]

          $variable

          $_POST['variable']

          Thanks for the help.

          Ken

          "Ken" <kkrolski@wi.rr .com> wrote in message
          news:IFN3c.6118 6$LD5.49426@twi ster.rdc-kc.rr.com...[color=blue]
          > What am I doing wrong?
          >
          > I set the variable co_name on the first page with an <input.... > and
          > session_start() at the top of both pages.
          >
          > Clicking on a link that takes me to the second page:
          >
          > Script on the second page.
          >
          > echo $_SESSION['co_name']; Does not display
          > value of co_name
          > echo "Variable name co_name = ".$co_name; Displays value of co_name
          >
          > One book suggested using echo {$_SESSION['co_name']}; Does not run.
          >
          > Server is Apache2 Triad
          >
          > Any suggestions. I would like to use $_SESSION incase I move to another
          > server without ??register_glob als?? ON
          >
          > Thanks for the help.
          >
          >[/color]


          Comment

          • Pedro Graca

            #6
            Re: $_SESSION vs. $variable

            Ken wrote:[color=blue]
            > What is the operational difference between
            >
            > $_SESSION['variable]
            >
            > $variable
            >
            > $_POST['variable'][/color]

            | creation | lifetime | scope
            ------------+------------------+----------------+---------
            $variable | first use | end of script | local
            $_POST[] | init (by client) | end of script | global
            $_SESSION[] | init (by server) | end of session | global

            I think this pretty much sums it up :)
            --
            --= my mail box only accepts =--
            --= Content-Type: text/plain =--
            --= Size below 10001 bytes =--

            Comment

            Working...