Jump to content

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


JustinK101

Recommended Posts

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

[code]

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);

[/code]

[b]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.[/b]
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

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.

[code]
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; }
    }
}
[/code]

[b]Then in my main class code I would simply call:[/b]

[code]
workOrder wo = new workOrder();
wo.Installer = "Installer Text Here";
wo.Address = "Some Address Here";
Etc....
wo.vins.Add("Vin1");
wo.vins.Add("Vin2");
Etc.....
[/code]
Link to comment
Share on other sites

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:

[code]
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;
[/code]

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

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#.
Link to comment
Share on other sites

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:

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

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.
[code]session_start();
print_r($_SESSION);
[/code]
Link to comment
Share on other sites

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

[code]
// 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
[/code]

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...
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[b] 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.. [/b]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.