SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2004
    Location
    Planet Earth
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing and array

    Hi

    I want to pass some variables from one page to another and I'm considering what is the best way to do it. Instead of having a long url&with&a&lot&of&variables, is it possible to create an array and pass it through and url?
    - - - - - - - - - - - - - -- - - - - - - - - - - -
    For example
    <? $List = array("one","two","three","four");?>

    <input type="hidden" name="list" value="<?php echo $List; ?>">

    and then
    goto.php?list=".$_POST['list']
    - - - - - - - - - - - - - - - - - - - - - - - - -

    I don't know if this is the best or the worst. If you have any comments I will appreciate it lots

    thanks



    ok
    "The Internet ? Is that thing still around ?"

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can't (AFAIK) directly pass a PHP array through a URL. What about using PHP session variables?

    PHP Code:
    //page1.php
    session_start();
    $_SESSION['List'] = array("one","two","three","four");

    //page2.php
    session_start();
    $List $_SESSION['List']; 
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hope you can manage the way as required but it is possible to pass like this:
    Code:
    http://www.yourdomain.com/page.php?my[]=1&my[]=2&my[]=3&my[]=4&my[]=5&my[]=6
    And get it like this:
    PHP Code:
    print "<pre>";
    print_r($_GET['my']);
    print 
    "</pre>"
    But still it is better to use SESSION.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    I'd pick serialize myself. It's a great way to pass arrays through the querystring.


Bookmarks

Posting Permissions

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