here’s a problem i consistently run into..
i am implementing a paypal service that takes the form of three files..
a file to gather the payment data…
a file to process the data, and make sure it is correct..
a file to provide api calls to paypal to process the payment..
the api samples do this the way most every other php script does..
via POST, they send the data to the next form..
in the receiving form, there are some agonizingly LONG strings of the following:
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
...and so on for ALL variables...
keep in mind that if you proceed this way, ANY time you update your inintial form, you will have to update ANY references to the $_POST call. this sucks..
i dug around for a bit.. and found this..
the first thing i did was take my $POST variables, and map them to $_SESSION variables. i thought for SURE this was alot tougher than i thought. it’s way easier.
session_start();
$_SESSION=$_POST;
will copy the array, and initialize the session variables..
since i used javascript to gussy the data up, there was really nothing to do on this end but to display the data and let the user go back and fix it if necessary..
here’s where it gets cool…
once we get to the api calls, we would, in all other cases, be required to initialize our variables again.. one by one.. based on the $_POST variable.. this SUCKS..
here’s a neat way to skate by this …
there is a command called session_encode() that will serialze your session variables..
once you serialze them, you can just unserialze them using unserialize() and you will in effect initialize all your $_SESSION variables as normal variables…
here’s how i did it:
$vars=session_encode();
print $vars; // do this once, just to see it work..
unserialize($vars);
at this point, you will see that you now have all your variables initialized..
keep in mind that if you change them, it has nothing to do with $_SESSION.. but in my case.. that wasn’t the gist of the thing.. all i needed was to make API calls with them without having to reference them via $_SESSSION..
in other words..
i can use:
$IPAddress
rather than
$_SESSION['IPAddress']
i thought that was pretty neat…
