Solved

Quick $_SESSIONS question

Posted on 2004-10-30
219 Views
Last Modified: 2008-03-17
Hi,
I have a quick sessions question, if I set a session on page1.php then go to some other site and come to page2.php

will the session still be there??

The reason I ask is this:
I want to set a session in "register_step_2.php" called "client_id" then the client goes to 2checkout .com fills in the payment details etc and gets directed to "register_step_3.php" where i want to read the session values again...

Thanks,
Mag
0
Question by:mag1c1an
    12 Comments
     
    LVL 27

    Assisted Solution

    by:Diablo84
    yes

    Session data will be available as long as the browser window is open, so if they go to your site, navigate away and then come back again the data will still be available. The data will only be lost if they close their browser.
    0
     
    LVL 2

    Author Comment

    by:mag1c1an
    Hi Diablo,
    Thanks for replying.

    I have been reading about sessions in the manual and it says that the session is stored on the users disk as a cookie, so if cookies are turned off I suppose that it gets written to the URL string as PHPSESSID...if thats the case, I cannot pass that sessid to 2checkout so how do i get back the session?

    Am i missing something or is there another way?

    Thanks,
    Mag
    0
     
    LVL 12

    Accepted Solution

    by:
    Hi Mag

    Session across domains causes issues, normally the session will not be recognize when you go to 2Checkout and then back to your site. You will need a word around for it.

    Have a look the replies at http:Q_21155588.html about SESSION ACROSS DOMAINS on 2CHECKOUT

    regards-

    0
     
    LVL 2

    Author Comment

    by:mag1c1an
    Hi MiniChicken,
    I guess I have no choice...will store the session variable in a table and send the client_id of the table to 2co, then on the other side query the db for those varables etc....

    Thanks,
    Mag
    0
     
    LVL 12

    Expert Comment

    by:minichicken
    Hi Mag

    I suppose so, need to do a work around.... well, at least that how I got it to work... :)
    0
     
    LVL 12

    Assisted Solution

    by:Ivanov_G
    > the session is stored on the users disk as a cookie.

    Not exactly... There are just cookies and "session cookies". Cookies output a file on your HDD, while session cookies don't. For session cookies there are files server-side. If you see in your PHP.ini file, you can find something like session.save_path = C:\WINNT\TEMP\. When you call session_start() go in this folder and see how a new file has been created. But this is on the SERVER, not on client machine.

    In IE, Tools / Options / Privacy / Advanced. There you see the settings for the session cookies.

    > will store the session variable in a table and send the client_id

    Implementing just DB-aware session will take you a lot of time. In Perl you have packages which use DB to store sessions, but in PHP ... I haven't heard. So you can find statistic about how many people have disabled session cookies. BTW recently I red some stats from WebCounter website. The result was less than 0,5%.
    0
     
    LVL 2

    Author Comment

    by:mag1c1an
    Hi,
    Thanks for replying.

    I didnt know about those server side cookies...learning something everyday :-)

    Anyway, 2checkout REALLY sucks, the variable gets passed sometimes and sometimes...its just blank, I have check (manually) and its not my programs fault...so now am trying to do it with just client side cookies, if cookies are not being set, output an error message and ask the client to put cookies on...

    :-(

    Mag
    0
     
    LVL 7

    Assisted Solution

    by:BenMorel
    For each session, the navigator has to remember your session ID.
    If the IE "security" level is high, it won't.

    To avoid this, redirect the user after payment to this url :
    $url = 'register_step_3.php?' . SID; // SID is a constant, let it outside the string

    Note: SID will *always* be declared as soon as the session is started.
    it's an empty string is your server has detected a session cookie, it's the url variable otherwise (i.e. PHPSESSID=xxxxxxx)

    Regards,
    Ben
    0
     
    LVL 12

    Expert Comment

    by:Ivanov_G
    You can use GET parameters. On the first page register_step_1.php you generate somehow the session ID - you can use IP, date and make a MD5 for this string. So the link for step 2 will be register_step_2.php?sid=2iut5ilkjehjgsdgjdshgks and on next page you will :
    $sid = $_GET['sid'];
    Then pass it to step_3, and so on.

    Thus the session will be independent from cookies.
    0
     
    LVL 10

    Assisted Solution

    by:eeBlueShadow
    Ivanov_G,

    The problem is that the user is redirected to a third party site, rather than staying within the site. So, the session ID can't be passed as there is a 'break in the chain' from page to page.
    0
     
    LVL 2

    Author Comment

    by:mag1c1an
    Hi Guys,
    Since I am using the recurring part of 2co, I finally settled on this solution:

    I am just takeing the values of the 4 variables in the session (for the sake of this example var1,var2,var3, var4) and passing it on to the merchant_order_id...

    eg:
    merchant_order_id=$var1."_".$var2."_".$var3."_".$var4

    and in the final page I am doing an explode on the underscore and takeing the variables out again


    Not the best of solutions...but its working :-)

    I hope this helps someone else in future.

    Cheers,
    MAg
    0
     
    LVL 2

    Author Comment

    by:mag1c1an
    Since I didnt really get the answer from any one...am increasing the points and splitting it...

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    As you all know PHP got one problem, before using other files classes or functions you need to include or use require function. But now in PHP 5 there's solution for this, it's called __autoload() function. You can read more about function in PHP ma…
    Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now