Current location: Hot Scripts Forums » Programming Languages » PHP » Continuing a session on a different server


Continuing a session on a different server

Reply
  #1 (permalink)  
Old 01-30-08, 07:43 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
Continuing a session on a different server

I am using paypal ipn to activate a script. The script relies on values set in sessions.

So:
  • User starts a session by adding items to cart on my website.
  • the items are stored in sessions and session arrays.
  • the user then goes to the checkout and is redirected to paypal.
  • Without ipn, the user would be redirected to my complete page and run the activation script from there which would work fine and does.
  • However, with ipn, the user submits the payment on paypal and then:
  • paypal posts info to my verify script
  • my verify script posts back to paypal
  • paypal runs my script assuming it verified it, but the session variables will be empty since the session cookies were stored on the users computer.

paypal then directs user back to complete page where no script is supposed to run.

End result: user pays for service and nothing is received.

In a nutshell, how can I get paypal to get the session contents without using a database?
__________________
Aye!
Reply With Quote
  #2 (permalink)  
Old 01-30-08, 07:49 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Generally if they're coming back to your page within any reasonable amount of time the session should still be viable regardless of where they've gone in the interim. Are you positive you're starting a session, or restarting it when they return?
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #3 (permalink)  
Old 01-30-08, 07:56 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
When posting to Paypal, can you send any variable you wish? Like:

html Code:
    <input type="hidden" name="mommy" value="My mommy is Vivian" />

And then Paypal returns that value?

If it is the case, you could send your session ID to Paypal, and when the session ID is returned, you can load that session.
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
  #4 (permalink)  
Old 01-30-08, 08:56 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
The problem is, the session stores the cart items in cookies on users pc.

Paypal runs the ipn verifications script which has to access the session cookies which populate a database with the cart items but paypal will not have access to the cookies since this all happens between my sites server and paypal, omitting the user.

By the time it gets back to the user, they will see the complete page with all the cart items listed as if everything worked.

Or are the items in the session stored on my server and just a session id in the users cookie?

If so, sending the session ID to paypal might work if I can recall the session in the verify script.

How do I get the session id and then set it as the session again later on?

Sorry for the quality of the picture:
  1. User adds items to cart stored in session arrays and clicks on "buy"
  2. User directed to paypal where they click on "pay now"
  3. User waits whilst paypal secretly contacts my server for verification and gets it and asks my server to run my verify script.
  4. my script runs using the values from the stored session variables and populates the database and sends emails etc... and hands the reigns back over to paypal
  5. paypal redirects the user to my server for summary of order

Because steps 3 and 4 are between paypal and my server, whatever is stored in the users session on their pc is not accessed. Hence, empty session variables when trying to populate my database.

I hope this and my drawing make things a bit clearer

ok. Sorry for all the questions. I have it sorted and working.

set custom field to post to paypal as session_id()

then added :
PHP Code:

session_id($_POST['custom']);

session_start(); 
at start of verify ipn file.

Let me know if there are any security issues with my methods though please.

thanks
Attached Images
File Type: jpg pic.jpg (9.3 KB, 87 views)
__________________
Aye!
Reply With Quote
  #5 (permalink)  
Old 01-30-08, 09:45 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
Well I don't think so. That was my proposal, and I'm glad it worked for you.

I would however choose anothe approach:

1. user buys item -> it goes in a temporary table, with a unique ID
2. payment is done via Paypal, set the unique ID from step 1 in the custom field
3. payment is being verified
4. if payment is verified, get the item from the temporary table via that unique ID you get back in $_POST["custom"]
5. store the item in the final table, and remove the item from the temporary table

That way you don't have to mess around with session stuff.
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
  #6 (permalink)  
Old 01-30-08, 11:02 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
I wish I had done it that way but it will take a lot of work to change it now.

Thanks for all your help
__________________
Aye!
Reply With Quote
  #7 (permalink)  
Old 01-31-08, 09:53 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
This is sort of a new problem but directly related to this post so I will stick it on here instead of creating a new thread.

PROBLEM: I can't seem to totally get rid of the session data.

My script takes an order, flies off to paypal and uses the session id to run my script and then comes back to my site where it is told to session_destroy()

The user can then go and place another order and instead of entering their details, they can log in and add their order to their account. That part works fine, however, when they receive their order confirmation email with the imploded shopping cart session, it has the old order on it aswell.

Is there some way to totally erase all session variables, session and session id?
__________________
Aye!
Reply With Quote
  #8 (permalink)  
Old 01-31-08, 10:16 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Hi deansatch. If you go to the session_destroy() function on php.net it also tells you that you need to delete the cookie as well to completely remove the session. Heres the code from the page
PHP Code:

  <?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
    
setcookie(session_name(), ''time()-42000'/');
}

// Finally, destroy the session.
session_destroy();
?>
Hope thats of some help

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #9 (permalink)  
Old 01-31-08, 10:19 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks

I tried that but it didn't work.

Will the cookie be stored on my pc, the web server or paypals server?
__________________
Aye!
Reply With Quote
  #10 (permalink)  
Old 01-31-08, 10:23 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
I have just checked, and it is sending a totally different session id to paypal for each order. If it is a different session, how come my session still implodes to show old variables?
__________________
Aye!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Security (Continued from post below) nova912 PHP 1 09-05-06 09:29 AM
GameWarrior.net High Performance Game Servers / Ventrilo gamewarrior General Advertisements 0 01-10-06 07:12 AM
Free web site, control panel, and dedicated IP with game server purchase for only $25 twastudios General Advertisements 3 10-20-05 06:13 AM
Free Server Security Audit by Touch Support TSGradyR General Advertisements 0 03-30-05 11:35 PM
FREE Team Speak server w/ every purchase of a Call of Duty Server twastudios General Advertisements 0 10-31-03 01:14 AM


All times are GMT -5. The time now is 07:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.