Jump to content


Photo

Is there a way to pass a session into a new window?


  • Please log in to reply
12 replies to this topic

#1 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 28 April 2006 - 06:07 PM

Currently I pass some form varibales in the 'getter' address bar into a new javascript popup window.


function centerWindow() 
                        {
                            leftPos = 0
                            topPos = 0
                                if (screen) 
                                {
                                    leftPos = (screen.width / 2) - 463;
                                    topPos = (screen.height / 2) - 350;
                                }
                        }
                
                        function makeNewWindow(url, name, width, height, cenLeft, cenTop)
                        {
                            parentWindow = window.open(url, name, 'width=' + width + ',height=' + height + ',toolbar=0, location=0, directories=0, status=0, menubar=1, scrollbars=1, resizable=false, left=' + cenLeft + ', top=' + cenTop +'');
                        }
                
                        centerWindow();
                        makeNewWindow("go_print_work_order.php?customer_id=<? echo $_GET['customer_id']; ?>&customer_name=<? echo $_GET['customer_name']; ?>&order_id=<? echo $_GET['order_id']; ?>&type=<? echo $_GET['type']; ?>&installer=<? echo $_GET['installer']; ?>&vins[]=<? if($vehicles != NULL) { foreach ($_GET['vehicles'] as $vehicle) echo $vehicle . '&vins[]='; } ?>&vehicle_instructions=<? echo urlencode($_GET['vehicle_instructions']); ?>&instructions=<? echo $_GET['instructions']; ?>", 'printWorkOrder', '925', '700', leftPos, topPos);


As you can see its quite a big freaken mess passing all the data manually. Is there anyway to store all my form data in one session in the current window, then just pass that session object to the new javascript form window? Then I would have access to all my variables through the passed in session in the new popup window. So basically I want to send an object, which stores all kinds of miscellanous data which then I can just get.

It would make my life soooo much easier. Thanks for the help.


#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 28 April 2006 - 06:13 PM

cookie?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 28 April 2006 - 06:34 PM

Ehhhh I want to stay away from cookies.

I code in C# using Visual Studio all the time, and if I were coding in that, I would create a new object which has all the variables I need as class members vars, then create a default constructor which sets all the variables equal to "". Then create get and set functions for each variable.

Then in my main form I would construct a new object of this class:

myClass instance = new myClass();

Then fill in all the values of the object, for example:


instance.first_name = "Justin";
instance.state = "California";

Then after all the values are filled, pass the object, instance, to the new window/form.

Somebody convert that to php? I don't usually ever code OOP in php so I have no idea. Thanks!

#4 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 28 April 2006 - 11:48 PM

Anybody know? :)

Maybe I can write some c#, because this is how I know how to do it, and some kind soul can convert my C# to php. I really need to learn OOP in php and converting this would really help me. I must admit, I LOVE how C# does some things.

class workOrder
{
    private string installer;
    private string address;
    private string city;
    private string state;
    private string zip;
    
    //This is probably a C# specific container.
    public ArrayList vins;
    
    //Constructor
    public workOrder()
    {
        installer = "";
        address = "";
        city = "";
        state = "":
        zip = "";
        vins = new ArrayList();
    }
    
    //GET & SET Property
    public string Installer
    {
        get { return installer; }
        set { installer = value; }
    }
    
    //GET & SET Property
    public string Address
    {
        get { return address; }
        set { address = value; }
    }
    
    //GET & SET Property
    public string City
    {
        get { return city; }
        set { city = value; }
    }
    
    //GET & SET Property
    public string State
    {
        get { return state; }
        set { state = value; }
    }
    
    //GET & SET Property
    public string Zip
    {
        get { return zip; }
        set { zip = value; }
    }
}

Then in my main class code I would simply call:

workOrder wo = new workOrder();
wo.Installer = "Installer Text Here";
wo.Address = "Some Address Here";
Etc....
wo.vins.Add("Vin1");
wo.vins.Add("Vin2");
Etc.....


#5 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 28 April 2006 - 11:59 PM

so why not just use the $_SESSION variable?

#6 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 29 April 2006 - 10:59 PM

Cause it is my understanding that sessions cannot be passed to new windows. They only 'live' in their current context and when you close the window they expire.

Also how would I pass a session that had lots of vars in one session? For example:

session_register("session_installer");
session_register("session_address"); 
session_register("session_city");
session_register("session_state"); 
$session_installer = $row['installer'];
$session_address = $row['address'];
$session_city = $city;
$session_state = $state;

Then how would I reference this whole collection? It seems to me, the solutions is to create the class above in C# in php.

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 April 2006 - 12:05 AM

backing up a few steps .... isn't this the perfect application for a simple cookie?
Legend has it that reading the manual never killed anyone.
My site

#8 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 30 April 2006 - 12:38 AM

Well, it doesnt make sense to use a cookie, because all I want to do is simply pass variables along to a new browser window. I dont need to store values, and also some of the values are senstive and don't want them stored in a cookie.

Also, I need to be able to store many vins which users choose out of a textarea. So vins is an array of vins, hence why in my implementation of the c# class I used a ArrayList. Can you even store an array of vins in a cookie?

To me, this is the perfect place to take advantage of OOP and pass an object of type workOrder to the new window. Again, though I don't know how to go about this in PHP, though I do it all the time in C#.

#9 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 30 April 2006 - 01:18 AM

I'm sorry if this just seems too obvious to me... I might be missing something -- let me know if I'm just off in left field.

A session array could be set like this:

session_start();
$_SESSION['installer']=$row['installer'];
$_SESSION['address']=$row['address'];
$_SESSION['session_city']=$city;
$_SESSION['session_state']=$state;

then in your popup window, just make sure you start your session before you do anything else, and the variables are magically available.

here's a very simple test page you can use as a popup -- just to see the contents of your $_SESSION array.
session_start();
print_r($_SESSION);


#10 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 30 April 2006 - 04:19 AM

Just some comments that may help...

1. you CAN use sessions to pass values when opening a new broswer window. (ie target="_blank")

2. there is an easy way to gather all of your user defined variables into a session variable

// store all the user defined variables into an array  
$my_vars = get_defined_vars ( );  
// store the array into the session  
$_SESSION['my_vars'] = $my_vars;  
// proceed to the next page 

3. this one I really have not figured out yet, but it appears that you can also use the session id to access the variables contained in a particular session. (perhaps someone could elaborate on how to do this).

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#11 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 30 April 2006 - 05:36 AM

OK I will try setting the session vars and then see if I can access them in the new popup. I don't do a new popup via target=_new though, I do it through javascript. I'll let you guys know, but my feeling is the session vars wont be defined in the new window.

#12 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 30 April 2006 - 07:11 PM

If you start the session (and the user has cookies turned on) it will work fine. You could also pass the session ID in the URL.

more info on sessions is available on the PHP site:
[a href=\"http://us2.php.net/manual/en/ref.session.php\" target=\"_blank\"]http://us2.php.net/manual/en/ref.session.php[/a]

#13 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 02 May 2006 - 07:44 PM

You guys were completely right about sessions working/being available in new popup windows. I was able to reference everything I needed from the session created in the parent window. Thanks..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users