send variables via session variable instead of post or get

Discussion in 'PHP' started by Kyriakos, Jun 10, 2008.

  1. #1
    hi,

    i hava a php page and i want to send some variables and i wand to pass variables via session variable instead of post or get. this is my php code:
    <?php
    include("connection.php");
    $pid = $_GET['pid'];
    $sl = $_GET['sl'];
    ?>
    
    pages.php?pid=<?php echo $row['pid'];?>&sl=<?php echo $row['sl'];?>
    PHP:
    can anybody convert this for sending variables via session?

    thanks in advance.
     
    Kyriakos, Jun 10, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    try:

    
    
    <?php
    session_start();
    include("connection.php");
    $_SESSION['pid'] = $_GET['pid'];
    $_SESSION['sl'] = $_GET['sl'];
    ?>
    
    pages.php
    
    
    PHP:
    On the pages.php page:

    
    
    <?php 
    session_start();
    
    $pid = $_SESSION['pid'];
    $sl = $_SESSION['sl'];
    
    //Use these as needed.
    ?>
    
    PHP:
    You should at some point clean the initial $_GET variables to make sure that a user isn't putting any malicious code in them.
     
    jestep, Jun 10, 2008 IP