This topic is locked

Pass parameters to PHPRunner project from a third party website

10/22/2025 21:49:52
PHPRunner General questions
J
jacktonghk authorDevClub member

I hce tried to use session variable and get variables but none of them work. Anyone knows how to do it? Many thanks.

Best regards,
Jack Tong

ChatGPT 10/22/2025

Hi Jack,

Using session variables and GET variables in PHPRunner can be a bit tricky if you're not familiar with how the framework handles them. Here’s a quick guide on how to use both types of variables in PHPRunner.

Using Session Variables

  1. Setting a Session Variable:
    You can set a session variable in PHPRunner using PHP code. For example, you can set a session variable in the Before Process event of a page:

    session_start();
    $_SESSION['my_variable'] = 'some_value';

  2. Retrieving a Session Variable:
    To retrieve a session variable, you can use it in any PHP code block. For example, in the Before Display event:

    session_start();
    $value = isset($_SESSION['my_variable']) ? $_SESSION['my_variable'] : 'default_value';


Using GET Variables

  1. Accessing GET Variables:
    GET variables can be accessed directly via the $_GET superglobal array. For instance, if you have a URL like yourpage.php?var=value, you can access the variable like this:

    $value = isset($_GET['var']) ? $_GET['var'] : 'default_value';
  2. Using GET Variables in Events:
    You can use GET variables in various events, like Before Process, Before Display, or wherever you need to use them. Just remember to sanitize any input you get from URL parameters to avoid security issues.



Example Usage

Here's an example of how you might use both session and GET variables together:

// In Before Process event
session_start();
if (isset($_GET['user_id'])) {
$_SESSION['user_id'] = $_GET['user_id'];
}

// In Before Display event
session_start();
$user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : 'no user';
echo "Current User ID: " . htmlspecialchars($user_id);

Troubleshooting

  • Ensure Sessions are Started: Always call session_start() before trying to access session variables.
  • Check URL Parameters: Make sure that your GET variables are actually being passed in the URL.
  • Debugging: Use var_dump() or similar functions to check the contents of $_SESSION and $_GET.

If you are still having issues, please provide more details about what you are trying to achieve, and I can offer more specific help.

Best regards,
[Your Name]