[PHP] Playing with globals

2004-05-28 Thread Ciprian Trofin
Hi All,

My system: Windows NT 5.0 build 2195 / Apache/1.3.23 - PHP 4.1.1

Here is a nice snippet:
___
?
function test() {
 $GLOBALS['test'] = 1;
 $test = 2; }

test();
echo $test;
?
__

the result: 1 (however, I expected to see 2)




If I change to:
?
function test() {
 global $test;
 $GLOBALS['test'] = 1;
 $test = 2; }

test();
echo $test;
?
___

the result: 2

I understand the concept o local and global variables, but isn't $GLOBALS
supposed to work as an alternative to global statement ? 


--
Best regards,
  Ciprian

 Teamwork is essential. It allows you to blame someone else.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] unset() un-appropriate ?

2003-10-13 Thread Ciprian Trofin

I have a form with 3 checkboxes x1,x2,x3. I want to build an array of
values from the checked boxes; I choosed the following approach:
1. build an array with all values
2. eliminate from array the  values using unset

CODE:

  $x = array($_POST['x1'],$_POST['x2'],$_POST['x3']);
  do {
   for ($i=0;$i  sizeof($x);$i++) {
$stop = 0;
if (!trim($x[$i])) {
 $stop = 1;
 unset($x[$i]);
 break;
}
   }
  }
  while ($stop0);


For some reason, the code doesn't work (loops ad infinitum). But replacing

unset($x[$i]);

with

array_splice($indice, $i, 1);

it does.

Help!

-- 
 Ciprian

 Remember that you are unique. Just like everyone else.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Restricted access

2003-08-14 Thread Ciprian Trofin
Hi All,

I want to give access to resources (PDFs and some RTFs) only to registered
users and I also want to deny that kind of access to people that guess
the URL. I guess it is all about putting these files outside the web-tree
and somehow putting PHP to work.

Could you enlighten me ? :))

--
Thnx,
Cip


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Restricted access

2003-08-14 Thread Ciprian Trofin
What is readfile90 ? I tried google and nothing.
MK Yes, put the files outside of web root or protect them using .htaccess 
MK file. After authorization use readfile90 to serve the file. There are 
MK lots of tutorials on authentization and if you are using some CMS you 
MK might have all you need.

 I want to give access to resources (PDFs and some RTFs) only to registered
 users and I also want to deny that kind of access to people that guess
 the URL. I guess it is all about putting these files outside the web-tree
 and somehow putting PHP to work.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Incrementing counter from an HTML page.

2003-07-04 Thread Ciprian Trofin
Suggestions:
1. use a picture for the counter (with the image - handling library)
2. use a javascript script :)
script language=JavaScript src=script.php
this script will return the hit-counter in a variable that you can use.

Question: why no redirects ?


P Glory!
 
P The problem I am facing is that my Index page can be an HTML page only..
P not PHP. I cant use framesets, redirects etcetera. 
P I want to build my own Counter using PHP  mySQL Database.. with the
P Users Online and Total Hits feature. 
P How can I increment the counter or affect a PHP code using HTML.. is
P there someway I can achieve this? To be able to show the php counter on
P my HTML page.. ?


-- 
 Ciprian

 Confucius Says: Man with hand in pocket is having a ball.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Bug ?

2003-04-05 Thread Ciprian Trofin
David, thank you very much. I suspected smth. like this, but still, it is
weird: PHP already has the  operator (?) for assigning by reference. And
there is more: I noticed that if I use the sort function instead of
array_multisort, it works as expected.

I still think there is a bug involved :(

I tried something like this:

?
$arrayA = array(5,4,3,2,1);
$arrayB = $arrayA;
array_multisort($arrayA);
echo $arrayA[0], br;
echo $arrayB[0];
?


The output is:
1
1

I think it should be:
1
5

DO It's not a bug (ie this is expected behaviour in PHP4 for various
DO sensible reasons), but it can sometimes throw up odd effects if you're
DO not expecting it.

DO What you're running into here is the difference between a deep copy
DO (make a copy of a piece of memory) and a shallow copy (make two
DO variables point to the same piece of memory).

DO The way to think of it is that $arrayA doesn't actually contain your
DO array values - it contains a reference (a pointer in C-speak) to the
DO memory location where the array values are stored. The line

DO $arrayB = $arrayA;

DO is copying the reference, not the values. You can run up against this
DO behaviour in quite a few of the post-C++ languages, and it can be
DO disconcerting if you're used to languages where copies are all deep
DO unless flagged otherwise.

DO To add insult to injury, some array operations can implicitly cause a
DO deep copy to be made. Try this, which adds one extra line:

DO ?
DO function echo_array($a) {
DO foreach ($a as $v) {
DO echo ($v);
DO echo (', ');
DO }
DO echo (br);
DO }
DO $arrayA = array(5,4,3,2,1);
DO $arrayB = $arrayA;
DO $arrayA[] = 6; // this line added
DO array_multisort($arrayA);
DO echo_array($arrayA);
DO echo_array($arrayB);
?

DO More details (maybe) here:

DO http://www.zend.com/zend/art/ref-count.php




-- 
 Ciprian

 Un cuvant de sfarsit:
 A cynic knows the price of everything  value of nothing


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Bug ?

2003-04-04 Thread Ciprian Trofin
I tried something like this:

?
$arrayA = array(5,4,3,2,1);
$arrayB = $arrayA;
array_multisort($arrayA);
echo $arrayA[0], br;
echo $arrayB[0];
?


The output is:
1
1

I think it should be:
1
5



Systems tested:
Windows 98 / PHP 4.2.2
Windows 2000 SP3 / PHP 4.1.1


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php