This topic is locked
[SOLVED]

  Global Variables

6/18/2013 5:30:59 PM
PHPRunner General questions
H
headingwest author

Hi, I'm a long time programmer new to PHP and PHPrunner.
Is it possible to have global variables?
In my case I want to filter the where clause based on the user login. So save some parameters into a variable that I can use on multiple pages. The variable is a string that gets built in the "after successful login" event.
ALSO - is there some documentation on programming for PHPrunner or should I be reading up on PHP programming in general? The help file doesn't cover variables etc.
Thanks for your help.

C
cgphp 6/18/2013

Session variables are what you are looking for.
In the "After successful login" event enter the following code:

$_SESSION['my_custom_var'] = 'My custom value';


In the "Before SQL query" event of a list page, enter the following code:

$strWhereClause = whereAdd($strWhereClause, "you_field_name = '" . $_SESSION['my_custom_var'] . "'");


Replace the "my_custom_var" associative key with a name you like, and replace 'My custom value' with a valid string value.

H
headingwest author 6/18/2013

Thank you Cristian,
I put the following into Login:After Successful Login

$_SESSION['my_custom_var'] = 'My custom value';


Then I tried to test it in table:Before Display

echo "This is a test message to show ... ";

echo($_SESSION['my_custom_var']);

print_r ($_SESSION['my_custom_var']);


The first "test message" was displayed but not the second two messages.
Also

print_r ($_SESSION);

shows a lot of session variables but not my_custom_var
Am I doing this correctly??

C
cgphp 6/18/2013

echo does not behave like a function. Please, fix your code as follows:

echo "This is a test message to show ... ";

echo $_SESSION['my_custom_var'];

print_r($_SESSION['my_custom_var']);


MAKE SURE TO PERFORM A BUILD OF THE PROJECT!!!

H
headingwest author 6/18/2013

hhhmmm. This works if I set the SESSION in Menu page:Before Display
I can then echo in the table:list page:before display
But if I set the SESSION variable in After Successful Login - nothing!
I've done a full build, logged out/in and restarted Firefox.
So why isn't my SESSION variable saving in After Successful Login??

C
cgphp 6/18/2013

Do you have a redirection code or something similar in the "After Successful Login" event before the SESSION var?

H
headingwest author 6/18/2013



Do you have a redirection code or something similar in the "After Successful Login" event before the SESSION var?


Yes! I managed to put the function name twice. Fixed now and thank you for all your help.