Re: [PHP-DB] Sharing variable values among PHP files
Coments inline... snip On 01 Apr,2003 at 10:04 Mustafa Ocak wrote: You can store the value in a session variable session_start(); if (isset($_HTTP_SESSION_VARS['your_variable_name'])) { /snip Rather than using isset() you may need to use session_is_registered(). This is specifically for checking the existence of a session variable. I would do something like ?php // need this on all pages where you want to work with // the session var session_start(); // Check for the existence of the session var and create // it if it doesn't exist if (!session_is_registered(ses_username)) { session_register(ses_username); } // Are we getting a form var thru ? if so pop it into the session var if (isset($frm_username)) { $ses_username = $frm_username; } // then in your scripts you can do do_my_amazing_function($ses_username); ? As long as you have session_start() at the beginning of each script, $ses_username is now available across scripts. snip $value=$_HTTP_SESSION_VARS['your_variable_name']; //get the value }else{ $_HTTP_SESSION_VARS['your_variable_name']=new value; } /snip Hope that helps. -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing variable values among PHP files
Please, please, PLEASE don't give advice! If you don't know the answer, DON'T COMMENT! The method you posted is for register_gkobals on, which it won'tr always (and shouldn't be)! Ronan Chilvers wrote: Coments inline... snip On 01 Apr,2003 at 10:04 Mustafa Ocak wrote: You can store the value in a session variable session_start(); if (isset($_HTTP_SESSION_VARS['your_variable_name'])) { /snip Rather than using isset() you may need to use session_is_registered(). This is specifically for checking the existence of a session variable. I would do something like ?php // need this on all pages where you want to work with // the session var session_start(); // Check for the existence of the session var and create // it if it doesn't exist if (!session_is_registered(ses_username)) { session_register(ses_username); } // Are we getting a form var thru ? if so pop it into the session var if (isset($frm_username)) { $ses_username = $frm_username; } // then in your scripts you can do do_my_amazing_function($ses_username); ? As long as you have session_start() at the beginning of each script, $ses_username is now available across scripts. snip $value=$_HTTP_SESSION_VARS['your_variable_name']; //get the value }else{ $_HTTP_SESSION_VARS['your_variable_name']=new value; } /snip Hope that helps. -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.
Re: [PHP-DB] Sharing variable values among PHP files
Hi Leif On 01 Apr,2003 at 3:07 Leif K-Brooks wrote: snip Please, please, PLEASE don't give advice! If you don't know the answer, DON'T COMMENT! The method you posted is for register_gkobals on, which it won'tr always (and shouldn't be)! /snip No need to be rude ... its very easy to adjust this code so that it doesn't need register_globals. The logic of the code is the point. I simply offered an alternative way of handling session vars that I feel is cleaner and clearer. Please don't go off the deep end with replies. There's no need. If you felt that you should point out the register_globals issue, then a simple 'Don't forget register_globals needs to be turned on here and it probably isn't' would suffice. While I am not a php guru (as you seem to be) I have been working with it for a long time commercially and do have some experience, so I am occasionally able to offer pointers on people's questions and offer such advice freely, in the hope that it will help. Lets all be adults, shall we ? You don't get any points for flaming. We're here to learn not fight. snip Ronan Chilvers wrote: Coments inline... snip On 01 Apr,2003 at 10:04 Mustafa Ocak wrote: You can store the value in a session variable /snip -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing variable values among PHP files
For us novices, can you please share how you would do this with register_globals off? At 01:07 AM 4/1/2003, you wrote: The method you posted is for register_gkobals on, which it won'tr always (and shouldn't be)! Ronan Chilvers wrote: Coments inline... snip On 01 Apr,2003 at 10:04 Mustafa Ocak wrote: You can store the value in a session variable session_start(); if (isset($_HTTP_SESSION_VARS['your_variable_name'])) { /snip Rather than using isset() you may need to use session_is_registered(). This is specifically for checking the existence of a session variable. I would do something like ?php // need this on all pages where you want to work with // the session var session_start(); // Check for the existence of the session var and create // it if it doesn't exist if (!session_is_registered(ses_username)) { session_register(ses_username); } // Are we getting a form var thru ? if so pop it into the session var if (isset($frm_username)) { $ses_username = $frm_username; } // then in your scripts you can do do_my_amazing_function($ses_username); ? As long as you have session_start() at the beginning of each script, $ses_username is now available across scripts. snip $value=$_HTTP_SESSION_VARS['your_variable_name']; //get the value }else{ $_HTTP_SESSION_VARS['your_variable_name']=new value; } /snip Hope that helps. -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing variable values among PHP files
Hi Leston In case Leif, doesn't get back to you, here's a way to do it (inline). Similar to what Mustafa has already posted:- On 01 Apr,2003 at 8:35 Leston Drake wrote: snip For us novices, can you please share how you would do this with register_globals off? /snip snip ?php // need this on all pages where you want to work with // the session var session_start(); // Check for the existence of the session var and create // it if it doesn't exist if (!session_is_registered(ses_username)) { /snip // Check if session var is set if (!isset($HTTP_SESSION_VARS[ses_username])) { // check to see if we have a posted var from form if (isset($HTTP_POST_VARS[frm_username])) { // We have no session var and a form var // waiting for us $HTTP_SESSION_VARS[ses_username]=$HTTP_POST_VARS[frm_username]; } } // Now $HTTP_SESSION_VARS[ses_username] exists and contains // the username snip session_register(ses_username); } // Are we getting a form var thru ? if so pop it into the session var /snip You can shorten $HTTP_SESSION_VARS to $_SESSION if PHP version 4.1.0. Cheers -- Ronan e: [EMAIL PROTECTED] t: 01903 739 997 w: www.thelittledot.com The Little Dot is a partnership of Ronan Chilvers and Giles Webberley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing variable values among PHP files
The method posted, using isset(). Leston Drake wrote: For us novices, can you please share how you would do this with register_globals off? At 01:07 AM 4/1/2003, you wrote: The method you posted is for register_gkobals on, which it won'tr always (and shouldn't be)! Ronan Chilvers wrote: Coments inline... snip On 01 Apr,2003 at 10:04 Mustafa Ocak wrote: You can store the value in a session variable session_start(); if (isset($_HTTP_SESSION_VARS['your_variable_name'])) { /snip Rather than using isset() you may need to use session_is_registered(). This is specifically for checking the existence of a session variable. I would do something like ?php // need this on all pages where you want to work with // the session var session_start(); // Check for the existence of the session var and create // it if it doesn't exist if (!session_is_registered(ses_username)) { session_register(ses_username); } // Are we getting a form var thru ? if so pop it into the session var if (isset($frm_username)) { $ses_username = $frm_username; } // then in your scripts you can do do_my_amazing_function($ses_username); ? As long as you have session_start() at the beginning of each script, $ses_username is now available across scripts. snip $value=$_HTTP_SESSION_VARS['your_variable_name']; //get the value }else{ $_HTTP_SESSION_VARS['your_variable_name']=new value; } /snip Hope that helps. -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Sharing variable values among PHP files
You could set a cookie containing the value on the first page and access it on the others. -Original Message- From: Alexa Kirk [mailto:[EMAIL PROTECTED] Sent: Monday, March 31, 2003 6:35 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: [PHP-DB] Sharing variable values among PHP files Does anyone know how to take a variable containing POST data from a form and use this value in another PHP file? I need to take a username from one PHP file and use it in a couple of other PHP files later when adding to a database. Thank you, Alexa Kirk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Sharing variable values among PHP files
You can store the value in a session variable session_start(); if (isset($_HTTP_SESSION_VARS['your_variable_name'])) { $value=$_HTTP_SESSION_VARS['your_variable_name']; //get the value }else{ $_HTTP_SESSION_VARS['your_variable_name']=new value; } You can use this script to pass values between pages. HTH Mustafa - Original Message - From: Alexa Kirk [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, April 01, 2003 5:35 AM Subject: [PHP-DB] Sharing variable values among PHP files Does anyone know how to take a variable containing POST data from a form and use this value in another PHP file? I need to take a username from one PHP file and use it in a couple of other PHP files later when adding to a database. Thank you, Alexa Kirk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php