How does one pass array variables between URLs?

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

    How does one pass array variables between URLs?

    I would like to pass array variables between URLs but I don't know
    how. I know its possible with sessions, but sessions can become
    useless if cookies are disabled. I have unsuccessfully tried using
    post and get methods.

    Thank you
    John
  • Nikolai Chuvakhin

    #2
    Re: How does one pass array variables between URLs?

    jkpmark@yahoo.c om (John) wrote in message
    news:<f63e2a2f. 0312201054.14ae b9f8@posting.go ogle.com>...[color=blue]
    >
    > I would like to pass array variables between URLs but
    > I don't know how.[/color]

    serialize() your array before passing it out and unserialize()
    it on the receiving end:

    Generates a storable representation of a value

    Creates a PHP value from a stored representation


    Cheers,
    NC

    Comment

    • Andy Hassall

      #3
      Re: How does one pass array variables between URLs?

      On 20 Dec 2003 10:54:38 -0800, jkpmark@yahoo.c om (John) wrote:
      [color=blue]
      >I would like to pass array variables between URLs but I don't know
      >how. I know its possible with sessions, but sessions can become
      >useless if cookies are disabled. I have unsuccessfully tried using
      >post and get methods.[/color]

      Use [] on the end of the variable name.

      whatever.php?x[]=1&x[]=2&x[]=3

      ... will produce a three-element array in $_GET['x'].

      --
      Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
      Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

      Comment

      • FLEB

        #4
        Re: How does one pass array variables between URLs?

        Regarding this well-known quote, often attributed to John's famous "20 Dec
        2003 10:54:38 -0800" speech:
        [color=blue]
        > I would like to pass array variables between URLs but I don't know
        > how. I know its possible with sessions, but sessions can become
        > useless if cookies are disabled. I have unsuccessfully tried using
        > post and get methods.
        >
        > Thank you
        > John[/color]

        You can still use sessions, and enable link-rewriting and hidden form
        elements to pass the session ID, along with the usual cookies. This is less
        secure, and could be more easily hijacked, but if the information you're
        sessioning doesn't need to be secret, it's probably no big deal.

        --
        -- Rudy Fleminger
        -- sp@mmers.and.ev il.ones.will.bo w-down-to.us
        (put "Hey!" in the Subject line for priority processing!)
        -- http://www.pixelsaredead.com

        Comment

        • Rahul Anand

          #5
          Re: How does one pass array variables between URLs?

          Andy Hassall <andy@andyh.co. uk> wrote in message news:<bfibuv8og sul3jtl37v8hmlq rop6mpu6o4@4ax. com>...[color=blue]
          > On 20 Dec 2003 10:54:38 -0800, jkpmark@yahoo.c om (John) wrote:
          >[color=green]
          > >I would like to pass array variables between URLs but I don't know
          > >how. I know its possible with sessions, but sessions can become
          > >useless if cookies are disabled. I have unsuccessfully tried using
          > >post and get methods.[/color]
          >
          > Use [] on the end of the variable name.
          >
          > whatever.php?x[]=1&x[]=2&x[]=3
          >
          > ... will produce a three-element array in $_GET['x'].[/color]

          You can even pass multi-dimensional associative array in similar way
          by using [] syntax.

          for example:

          whatever.php?my Arr[a][x]=1&x[a][y]=2&x[b][x]=3

          ... will produce

          $myArr = Array
          (
          [a] => Array
          (
          [x] => 1
          [y] => 2
          )

          [b] => Array
          (
          [x] => 3
          )

          )



          for secure array passing use *SESSION*

          -- Rahul

          Comment

          • CountScubula

            #6
            Re: How does one pass array variables between URLs?

            FLEB <soon.the.sp@mm ers.and.evil.on es.will.bow-down-to.us> wrote in message news:<1lvpda1on 2jx3.wv5v4zsn0l pe$.dlg@40tude. net>...[color=blue]
            > Regarding this well-known quote, often attributed to John's famous "20 Dec
            > 2003 10:54:38 -0800" speech:
            >[color=green]
            > > I would like to pass array variables between URLs but I don't know
            > > how. I know its possible with sessions, but sessions can become
            > > useless if cookies are disabled. I have unsuccessfully tried using
            > > post and get methods.
            > >
            > > Thank you
            > > John[/color][/color]

            Here is a little trick I use (I know, some people may not like it) but
            scripting with duct tape can be fun! Note: this does not work across
            site wide, unless you work it into all your links and pages, it is
            best for passing large data between few pages.

            ok fist thing you need to do is create an uniq ID for the user, and
            pass it along with the url. I tend to use:

            $sID = md5("some id text" . $_SERVER['SCRIPT_NAME'] . time());

            then on our links use:

            a href=/some_page.php?s id=<?php print $sID; ?>


            ok, now on your page that has the data, write it to a file (use a
            cache dir [make sure it is writeable])

            $sesFile = "_cache/$sID";
            // open the file, write php head
            $fp = fopen($sesFile, "w");
            fwrite($fp,"<?p hp\n");
            $wInfo = var_export($YOU R_ARRAY_NAME,TR UE);
            // write the var name and data
            fwrite($fp,"\$" ."YOUR_ARRAY_NA ME = "); // do not put $ on array name!
            fwrite($fp,$wIn fo.";\n");
            // write php end, and close file
            fwrite($fp,"?>\ n");
            fclose($fp);


            This creates a file that you can load right into a php script to have
            your array back

            so on the following page that you want your data array available on
            use this at the top

            $sID = $_GET['sid'];
            include("_cache/$sID");

            thats it, your array is now loaded and ready to use.

            ok, the bad side of this, writing files, and accumulating them, you
            need to find a way to delete these files that is best for you, you
            could delete the array after you load it, but there is a chance it
            wont delete, becouse they never went to the following page.

            I have a _cache dir on my server, and delete files over 30 days old,
            this could work for you, but then ties you into the server, and sites
            are not as portable.

            hope this helps,

            Mike Bradley
            http://gzen.myhq.info -- free online php tools

            Comment

            Working...