Re: [PHP] Where am i screwing up?
* Thus wrote Ryan A ([EMAIL PROTECTED]): > > foreach ($vars as $key) // clear all previous sessions > { > if(isset($_SESSION['$key'])) > { > unset($_SESSION['$key']); > } > } > echo "done1"; //just checking program execution No need to loop here, you can use an else statment in the next loop. And the key is inside '' as John pointed out. > > foreach ( $vars as $ ) // if any checkboxes were checked create a > session for them > { > ${$} = ( isset($_POST[$]) ? 1 : 0 ); > > if($==1) > { >$_SESSION[$]; >echo $; //getting no output from here...I just put it here for > testing > } > } Couple things: . Try not to use abstract names for vars (ie $), it makes the code harder to understand what its doing. But since this is a test script I'll let that slide :) . Your ${$} assingment is never used, read up on how to use variable variables. It isnt and shouldn't be used in this instance. . Try and make things a little simpliler: foreach ($vars as $) { if ( isset($_POST[$]) ) { $_SESSION[$] = 1; // be sure to assign a value. } else { unset($_SESSION[$]); // no single quotes around the key } } HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where am i screwing up?
From: "Ryan A" <[EMAIL PROTECTED]> > I am just screwing around and getting used to arrays with a "foreach" thanks > to Michael,Jan and Evan from this list and have run into problems. > > My requirment is pretty simple (code is below too) > 1)unset all the sessions that might have been set with reference to the > hardcoded array ($vars) > 2)if any checkboxes have been set from the previous form then set that > session > needless to say, its not working, am too new at this to know where my fault > is so any help is greatly appreciated. > > I have even added a few comments as to what i was thinkingtell me if i > was wrong. > > **Start code > $vars = Array('noPlatform','noPrice','noSfee','noSpace'); // this > corresponds to the "name=" of each checkbox > > foreach ($vars as $key) // clear all previous sessions > { > if(isset($_SESSION['$key'])) > { > unset($_SESSION['$key']); > } > } > echo "done1"; //just checking program execution > > foreach ( $vars as $ ) // if any checkboxes were checked create a > session for them > { > ${$} = ( isset($_POST[$]) ? 1 : 0 ); > > if($==1) > { >$_SESSION[$]; >echo $; //getting no output from here...I just put it here for > testing > } > } > echo "done2"; //just checking program execution > ?> > > End code How about you name your checkboxes as: name="setting[xx]" where xx is from your $vars array above. You'll end up with name="setting[noPlatform]" value="1" name="setting[noPrice]" value="1" etc... Now, you'll have $_POST['setting'] that'll contain the checked boxes. To put those in session: $_SESSION['setting'] = $_POST['setting']; To see which boxes were checked... $checked = array_keys($_POST['setting']); or $checked = array_keys($_SESSION['setting']); $checked now an array similar to your $vars above but it only contains the values that were checked. To find out which checkboxes were NOT checked, you could use: $not_checked = array_diff($vars,$checked); Easy, eh?? Hope that helps. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where am i screwing up?
"John Manko" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Can someone correct me on this if i'm wrong... > > try (meaning, I think that $vars as $keys will put the value into $key, > not the key itself): > > foreach ($vars as $key=>$value) // clear all previous sessions > { > if(isset($_SESSION['$key'])) > { > unset($_SESSION['$key']); > } > } This is no good, now it's going to delete $_SESSION['0'] and so on. This top function seems OK to me as it was, but using $val in stead of $key should be clearer. Ivo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where am i screwing up?
* Thus wrote John Manko ([EMAIL PROTECTED]): > Can someone correct me on this if i'm wrong... > > try (meaning, I think that $vars as $keys will put the value into $key, > not the key itself): > > foreach ($vars as $key=>$value) // clear all previous sessions > { > if(isset($_SESSION['$key'])) > { >unset($_SESSION['$key']); > } > } That is correct. Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where am i screwing up?
oh, don't forget, '$key' will not get evaluated. "$key" will. John Manko wrote: Can someone correct me on this if i'm wrong... try (meaning, I think that $vars as $keys will put the value into $key, not the key itself): foreach ($vars as $key=>$value) // clear all previous sessions { if(isset($_SESSION['$key'])) { unset($_SESSION['$key']); } } Ryan A wrote: Hi, I am just screwing around and getting used to arrays with a "foreach" thanks to Michael,Jan and Evan from this list and have run into problems. My requirment is pretty simple (code is below too) 1)unset all the sessions that might have been set with reference to the hardcoded array ($vars) 2)if any checkboxes have been set from the previous form then set that session needless to say, its not working, am too new at this to know where my fault is so any help is greatly appreciated. I have even added a few comments as to what i was thinkingtell me if i was wrong. **Start code foreach ($vars as $key) // clear all previous sessions { if(isset($_SESSION['$key'])) { unset($_SESSION['$key']); } } echo "done1"; //just checking program execution foreach ( $vars as $ ) // if any checkboxes were checked create a session for them { ${$} = ( isset($_POST[$]) ? 1 : 0 ); if($==1) { $_SESSION[$]; echo $; //getting no output from here...I just put it here for testing } } echo "done2"; //just checking program execution ?> End code Thanks in advance, -Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where am i screwing up?
Can someone correct me on this if i'm wrong... try (meaning, I think that $vars as $keys will put the value into $key, not the key itself): foreach ($vars as $key=>$value) // clear all previous sessions { if(isset($_SESSION['$key'])) { unset($_SESSION['$key']); } } Ryan A wrote: Hi, I am just screwing around and getting used to arrays with a "foreach" thanks to Michael,Jan and Evan from this list and have run into problems. My requirment is pretty simple (code is below too) 1)unset all the sessions that might have been set with reference to the hardcoded array ($vars) 2)if any checkboxes have been set from the previous form then set that session needless to say, its not working, am too new at this to know where my fault is so any help is greatly appreciated. I have even added a few comments as to what i was thinkingtell me if i was wrong. **Start code foreach ($vars as $key) // clear all previous sessions { if(isset($_SESSION['$key'])) { unset($_SESSION['$key']); } } echo "done1"; //just checking program execution foreach ( $vars as $ ) // if any checkboxes were checked create a session for them { ${$} = ( isset($_POST[$]) ? 1 : 0 ); if($==1) { $_SESSION[$]; echo $; //getting no output from here...I just put it here for testing } } echo "done2"; //just checking program execution ?> End code Thanks in advance, -Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where am I?
Ok. In the root of the Webserver (Win | Apache) I have a directory called images and one called about. /+root (Win=C:\Inetpub\wwwroot, Apache=/home/../../public_html +-about +-images I call a page in about (/about/index.php). One this page I have a script to open an image file and get the size. DOC_ROOT gives me /root/about. This can go down 'x' number of levels. How do I /root/ dir from anywhere in my site? Jeff "Martin Towell" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Doing a quick scan through the output of phpinfo() on my machine, I can see > any one of the following will give me the path (incl. filename of the > current script) > > $HTTP_SERVER_VARS["DOCUMENT_ROOT"] . $PHP_SELF > $HTTP_SERVER_VARS["SCRIPT_FILENAME"] > $HTTP_SERVER_VARS["PATH_TRANSLATED"] > > HTH > Martin > > -Original Message- > From: Jeff [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, December 18, 2002 3:00 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] Where am I? > > > No, I've been looking all day. I can get the information is I run the script > from the root, but what if I am in a sub-dir? > Jeff > > "Martin Towell" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > try doing a phpinfo() , somewhere in there it'll tell you > > > > Martin > > > > -Original Message- > > From: Jeff [mailto:[EMAIL PROTECTED]] > > Sent: Wednesday, December 18, 2002 2:34 PM > > To: [EMAIL PROTECTED] > > Subject: [PHP] Where am I? > > > > > > I'm using PHP 4.0.6. I am developing on Win98SE, and deployed on an Apache > > server. > > > > I need to find the actual path of the root directory. > > > > Windows: C:/Inetpub/wwwroot/ > > Apache: /home/dcent/public_html/ > > > > I've tried dirname(), basename(), etc. I just can't figure it out. > > Help. > > > > Jeff > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Where am I?
Doing a quick scan through the output of phpinfo() on my machine, I can see any one of the following will give me the path (incl. filename of the current script) $HTTP_SERVER_VARS["DOCUMENT_ROOT"] . $PHP_SELF $HTTP_SERVER_VARS["SCRIPT_FILENAME"] $HTTP_SERVER_VARS["PATH_TRANSLATED"] HTH Martin -Original Message- From: Jeff [mailto:[EMAIL PROTECTED]] Sent: Wednesday, December 18, 2002 3:00 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Where am I? No, I've been looking all day. I can get the information is I run the script from the root, but what if I am in a sub-dir? Jeff "Martin Towell" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > try doing a phpinfo() , somewhere in there it'll tell you > > Martin > > -Original Message- > From: Jeff [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, December 18, 2002 2:34 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Where am I? > > > I'm using PHP 4.0.6. I am developing on Win98SE, and deployed on an Apache > server. > > I need to find the actual path of the root directory. > > Windows: C:/Inetpub/wwwroot/ > Apache: /home/dcent/public_html/ > > I've tried dirname(), basename(), etc. I just can't figure it out. > Help. > > Jeff > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Where am I?
No, I've been looking all day. I can get the information is I run the script from the root, but what if I am in a sub-dir? Jeff "Martin Towell" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > try doing a phpinfo() , somewhere in there it'll tell you > > Martin > > -Original Message- > From: Jeff [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, December 18, 2002 2:34 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Where am I? > > > I'm using PHP 4.0.6. I am developing on Win98SE, and deployed on an Apache > server. > > I need to find the actual path of the root directory. > > Windows: C:/Inetpub/wwwroot/ > Apache: /home/dcent/public_html/ > > I've tried dirname(), basename(), etc. I just can't figure it out. > Help. > > Jeff > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Where am I?
try doing a phpinfo() , somewhere in there it'll tell you Martin -Original Message- From: Jeff [mailto:[EMAIL PROTECTED]] Sent: Wednesday, December 18, 2002 2:34 PM To: [EMAIL PROTECTED] Subject: [PHP] Where am I? I'm using PHP 4.0.6. I am developing on Win98SE, and deployed on an Apache server. I need to find the actual path of the root directory. Windows: C:/Inetpub/wwwroot/ Apache: /home/dcent/public_html/ I've tried dirname(), basename(), etc. I just can't figure it out. Help. Jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php