Set a request value on a link

Discussion in 'PHP' started by gil_e, Dec 20, 2007.

  1. #1
    I am having issues with using the $_SESSION[...] as it is timing out. My app would work if I could do something like the following:

    
    <?php
      // This value may come from a database, or a $_REQUEST variable already
      $itemVal = "Value Alpha";
    
      // Set a link to call the new page with the $_REQUEST variable set for ?item
      echo "<a href='newPage.php?item=".$itemVal."'>Go to new page</a>";
    ?>
    
    PHP:
    However, this does not seem to work as the ?item value is not showing up on the newPage.php being called.

    What is the proper way to set a request variable for the target page?
     
    gil_e, Dec 20, 2007 IP
  2. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To past variables between pages, you can use the POST or the GET method.
    In your example, you are using the GET method.

    use the phpinfo(); function on the newPage.php to see if you variables are passed.

    you should do some reading on the 'GET' and 'POST' method from the php.net site. It will be helpful.
     
    vonvhen, Dec 20, 2007 IP
  3. bsprogs

    bsprogs Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    In terms of using the session variable, I just wanted to verify that you have
    
    session_start();
    
    PHP:
    at the top of your page. Without it, you can't pass session data using the session superglobal variable.

    In terms of using the second example you provided, I wonder if having a space between the two words stored in the $itemVal variable is causing the issue.

    When you click the link created from
    
    echo "<a href='newPage.php?item=".$itemVal."'>Go to new page</a>";
    
    PHP:
    what does the URL actually look like on the next page?

    It should look something like
    http://www.domain.com/newPage.php?item=Value%20Alpha

    if not, try changing the value of your variable to something like this:
    
    $itemVal = "Value_Alpha"
    
    PHP:
    To get the value passed through the URL, you would want something like

    
    $getValue = $_GET['item'];
    
    PHP:
    That should set your $getValue variable with the value passed from "item" in the URL.
     
    bsprogs, Dec 20, 2007 IP
  4. gil_e

    gil_e Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    On the $_SESSION attempt, I was setting the session_start() at the top of the script...but it seems to be timing out after about 10 secs. Is there any way to make the session "never" time out? If so, then that may be my solution.

    The %20 should show up by the browser, so I don't think the under-score should be an issue. The value will be coming from a database anyway, so really should not be altering it.

    The way you showed the address is correct, that is what I "want" to show, however, there is nothing after the equals " = " sign...so there is no request value for the item.
     
    gil_e, Dec 21, 2007 IP
  5. coches

    coches Peon

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You understand that this variable you are using has nothing to do with sessions here,
    unless you assign it to a session variable.

    <?php
    session_start();
    // request is get and post and cookie global not session
    $_SESSION['somevalue'] = (isset($_REQUEST['somevalue'])  ) ? $_REQUEST['somevalue'] : 'defaultvalue';
    
    
    // now make the link with the session var
    PHP:
     
    coches, Dec 21, 2007 IP