php-general Digest 7 Jan 2010 03:09:18 -0000 Issue 6525

Topics (messages 300850 through 300863):

Re: Open source project management tool - PHP
        300850 by: Andrew Williams
        300853 by: Robert Cummings

SVG Won't Color?
        300851 by: Alice Wei
        300852 by: Ashley Sheridan

How to POST JSON data via PHP?
        300854 by: Rob Gould
        300855 by: shiplu

First time PHP user question
        300856 by: Rick Dwyer

PHP programming strategy; lots of little include files, or a few big ones?
        300857 by: clancy_1.cybec.com.au
        300858 by: Robert Cummings
        300859 by: Al

SVG and PHP
        300860 by: Bob Strasser
        300861 by: Bob Strasser
        300862 by: Bob Strasser

Site Moved From PHP4 to PHP5 Server - header, location no longer working
        300863 by: Vernon Webb

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
What could be a php potential problem with contact forms that are only
protected against SQL injections and have an admin side view for the
enquiry?

--- End Message ---
--- Begin Message ---
Angelo Zanetti wrote:
Thanks all, for the responses and advice.

After much research and trying out we decided to go with:
http://www.fengoffice.com/

its PHP based and also uses the EXTJS library. Its got quite a lot of
features (calendar, tasks, email, notes, documents, reporting) etc... with a
great AJAX interface and good functionality.

I'm using it within a government context and they're really enjoying it. I had a to make a few coding adjustments to facilitate a language switcher between English and French as is normal in a Canadian context. Additionally, due to the lack of folder hierarchy for documents (they rely on the tagging system which is inefficient for our document management) we are abusing the workspace system to provide the folder hierarchy. This necessitated a hack to prevent the aggregated view of all documents within sub-workspaces at parent workspace levels. If you're using 1.5 btw, you should update to 1.6 ASAP since it corrects some issues with inherited group permissions.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
Hi, 
  
  I have the code as in the following, and I am trying to colorize the map. The 
SVG File is located here: 
http://upload.wikimedia.org/wikipedia/commons/5/5f/USA_Counties_with_FIPS_and_names.svg.
 Looks like when I tried to modify the contents of the line, it does not seem 
to take into affect. Thus, my map does not get colorized. Do I have to save the 
file here? Or, is there something else I have missed here? 

<?php

//We are outputting an SVG
header("Content-type: image/svg+xml");

$array= array();
$array2= array();
$array3= array();
$array4= array();

#Map Colors
$colors_array= 
array("#F1EEF6","#D4B9DA","#C994C7","#DF65B0","#DD1C77","#980043");

 $file = file("unemployment09.csv");
 foreach ($file as $line) {
    $chars = preg_split("/,/", $line);
    $unemployment_rate = $chars[12];
    array_push($array,$unemployment_rate);   
  }

//Calculate the number of elements in array
$total_num = count($array);

#Load the Map
$ourFileName= "USA_Counties_with_FIPS_and_names.svg";
$fh = fopen($ourFileName, "r") or die("Can't open file");
$contents = fread($fh,filesize($ourFileName));
$lines2= file($ourFileName);

#Color the counties based on unemployment rate
for ($i=0;$i<$total_num;$i++){

  switch($array[$i]){
   
   case ($array[$i] > 10):
   $color = 5;
   break;   

   case ($array[$i] > 8):
   $color = 4;
   break;   
 
   case ($array[$i] > 6):
   $color = 3;
   break;   

   case ($array[$i] > 4):
   $color = 2;
   break;   

   case ($array[$i] > 2):
   $color = 1;
   break;   

   default:
   $color= 0;
   break; 

  }
  $color_class= $colors_array[$color];
  array_push($array4,$color_class);
}
   
foreach ($lines2 as $line_num => $line2) {

  $line_add_one = $line_num + 1;
  if(preg_match("/<path/",$line2)) {
   
   $rest = substr($lines2[$line_add_one],0,-3);
   $colors_style = ";color:" . $array4[$line_add_one];
   $rest = $rest . $colors_style . "\""; 
  }
  array_push($array3,$lines2[$line_add_one]);   
}

echo $contents;
fclose($fh); 

?>

Thanks for your help.

Alice
                                          
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/196390706/direct/01/

--- End Message ---
--- Begin Message ---
On Wed, 2010-01-06 at 11:27 -0500, Alice Wei wrote:

> Hi, 
>   
>   I have the code as in the following, and I am trying to colorize the map. 
> The SVG File is located here: 
> http://upload.wikimedia.org/wikipedia/commons/5/5f/USA_Counties_with_FIPS_and_names.svg.
>  Looks like when I tried to modify the contents of the line, it does not seem 
> to take into affect. Thus, my map does not get colorized. Do I have to save 
> the file here? Or, is there something else I have missed here? 
> 
> <?php
> 
> //We are outputting an SVG
> header("Content-type: image/svg+xml");
> 
> $array= array();
> $array2= array();
> $array3= array();
> $array4= array();
> 
> #Map Colors
> $colors_array= 
> array("#F1EEF6","#D4B9DA","#C994C7","#DF65B0","#DD1C77","#980043");
> 
>  $file = file("unemployment09.csv");
>  foreach ($file as $line) {
>     $chars = preg_split("/,/", $line);
>     $unemployment_rate = $chars[12];
>     array_push($array,$unemployment_rate);   
>   }
> 
> //Calculate the number of elements in array
> $total_num = count($array);
> 
> #Load the Map
> $ourFileName= "USA_Counties_with_FIPS_and_names.svg";
> $fh = fopen($ourFileName, "r") or die("Can't open file");
> $contents = fread($fh,filesize($ourFileName));
> $lines2= file($ourFileName);
> 
> #Color the counties based on unemployment rate
> for ($i=0;$i<$total_num;$i++){
> 
>   switch($array[$i]){
>    
>    case ($array[$i] > 10):
>    $color = 5;
>    break;   
> 
>    case ($array[$i] > 8):
>    $color = 4;
>    break;   
>  
>    case ($array[$i] > 6):
>    $color = 3;
>    break;   
> 
>    case ($array[$i] > 4):
>    $color = 2;
>    break;   
> 
>    case ($array[$i] > 2):
>    $color = 1;
>    break;   
> 
>    default:
>    $color= 0;
>    break; 
> 
>   }
>   $color_class= $colors_array[$color];
>   array_push($array4,$color_class);
> }
>    
> foreach ($lines2 as $line_num => $line2) {
> 
>   $line_add_one = $line_num + 1;
>   if(preg_match("/<path/",$line2)) {
>    
>    $rest = substr($lines2[$line_add_one],0,-3);
>    $colors_style = ";color:" . $array4[$line_add_one];
>    $rest = $rest . $colors_style . "\""; 
>   }
>   array_push($array3,$lines2[$line_add_one]);   
> }
> 
> echo $contents;
> fclose($fh); 
> 
> ?>
> 
> Thanks for your help.
> 
> Alice
>                                         
> _________________________________________________________________
> Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
> http://clk.atdmt.com/GBL/go/196390706/direct/01/


You're reading the SVG contents into $contents, and also into $lines2 as
an array. You seem to be making changes to the array version on a line
by line basis, but then you output $contents, which is the original
contents of the SVG file! You need to output the elements of $lines2,
either one-by-one, or concatenate the array into a string and output
that.

Also, as a bit of advice, I'd try to make your variable names a bit more
descriptive than $lines2, $line2, etc. Trying to read through the code
and remember what variable does what could be a massive headache later
on!

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message --- I've used curl before to post "field" data to a server, but in this case, I actaully need to post JSON data. However, when I run this PHP script, I get nothing back. If I do this curl manually in Terminal, it works.

I'm pretty sure the bug has something to do with CURLOPT_POSTFIELDS - - - I just don't know what the alternative is. Basically I need to post this data:

{siteUrl:\"http://testurl.com\",siteRss:\"http://feeds.news.mysite.com/synfeeds/collect/6/rss.xml \",userName:\"testuser\",email:\"testemail\",siteName:\"testsitename \",loginId:\"testloginid\}

to the url:

http://dpdev-ld03.myservercom:8181/linkmethod/signup?f=json&c=signupcallback


Any obvious mistakes below?




<?php
$ch = curl_init();
$timeout = 10; // set to zero for no timeout

$urltouse = "http://dpdev-ld03.myservercom:8181/linkmethod/signup?f=json&c=signupcallback ";

$fields_string = '{siteUrl:\"http://testurl.com\",siteRss:\"http://feeds.news.mysite.com/synfeeds/collect/6/rss.xml \",userName:\"testuser\",email:\"testemail\",siteName:\"testsitename \",loginId:\"testloginid\}';
        
curl_setopt($ch,CURLOPT_URL,$urltouse);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); <-- shouldn't be postfields, but some other curl option I'm guessing
        
$response = curl_exec($ch);
curl_close($ch);

echo $response;

?>
--- End Message ---
--- Begin Message ---
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query(array("data"=>$fields_string)));

Now on the server end $_POST['data'] will contain your json data.

if you just pass the $fields_string it can be read in the server end too.
$data = file_get_contents("php://input");
now $data will contain your json data.

It completely depends on the server you are interacting with. If it
needs json in a variable then pass it using http_build_query.
Otherwise just pass json as you are doing right now.

What you server expects?


-- 
Shiplu Mokaddim
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
SUST Programmers, http://groups.google.com/group/p2psust
Innovation distinguishes bet ... ... (ask Steve Jobs the rest)

--- End Message ---
--- Begin Message ---
Hello List.
I have been playing around with PHP, running a few tutorials and I came across an error message I could not resolve.

The tutorial is Generating One Time URL's by Oreilly:
http://www.oreillynet.com/pub/a/php/2002/12/05/one_time_URLs.html

Basically the PHP code is supposed to read from a text file and write to a text file and serve a text file all located in the "tmp" directory of the server.

However, I receive the error that the referenced files in the PHP code could not be found: "Warning: readfile(/tmp/secret_file.txt) [function.readfile]: failed to open stream: No such file or directory in/home/mysite/myfolder/ get_file.php on line 67"

Line 66 and 67 look like this:

$secretfile = "/tmp/secret_file.txt";
readfile($secretfile);


However, in the tmp folder, I have created a simple text file called "secret_file.txt" so I know it exists and it has the permissions set to 644, so it should be readable.

Can someone point out to me what I am doing wrong?  Thanks,


 --Rick



--- End Message ---
--- Begin Message ---
I have a flexible program, which can do many different things according to the 
type of
data it is fed.  Ideally the flexibility is achieved by calling different 
functions,
though when the functionality is ill-defined I sometimes just include blocks of 
code.

Ideally, from the point of program maintenance, each module should not be too 
long --
preferably just a page or so. This doesn't raise problems in a compiled 
language, but in
an interpreted language like PHP the programmer must decide whether to lump a 
whole lot of
functions into a single large include file, or to include lots of little files 
as the
particular functions are needed.

The first case can lead to memory bloat, as there are likely to be a lot of 
unused
functions in memory on any given pass, whereas the second case may require lots 
of little
files to be loaded.

Are there likely to be significant performance costs for either approach, and 
what are
your feelings about the relative virtues of the two approaches?

--- End Message ---
--- Begin Message ---
clanc...@cybec.com.au wrote:
I have a flexible program, which can do many different things according to the 
type of
data it is fed.  Ideally the flexibility is achieved by calling different 
functions,
though when the functionality is ill-defined I sometimes just include blocks of 
code.

Ideally, from the point of program maintenance, each module should not be too 
long --
preferably just a page or so. This doesn't raise problems in a compiled 
language, but in
an interpreted language like PHP the programmer must decide whether to lump a 
whole lot of
functions into a single large include file, or to include lots of little files 
as the
particular functions are needed.

The first case can lead to memory bloat, as there are likely to be a lot of 
unused
functions in memory on any given pass, whereas the second case may require lots 
of little
files to be loaded.

Are there likely to be significant performance costs for either approach, and 
what are
your feelings about the relative virtues of the two approaches?

Use a bytecode cache and stop worrying.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---


On 1/6/2010 7:18 PM, clanc...@cybec.com.au wrote:
I have a flexible program, which can do many different things according to the 
type of
data it is fed.  Ideally the flexibility is achieved by calling different 
functions,
though when the functionality is ill-defined I sometimes just include blocks of 
code.

Ideally, from the point of program maintenance, each module should not be too 
long --
preferably just a page or so. This doesn't raise problems in a compiled 
language, but in
an interpreted language like PHP the programmer must decide whether to lump a 
whole lot of
functions into a single large include file, or to include lots of little files 
as the
particular functions are needed.

The first case can lead to memory bloat, as there are likely to be a lot of 
unused
functions in memory on any given pass, whereas the second case may require lots 
of little
files to be loaded.

Are there likely to be significant performance costs for either approach, and 
what are
your feelings about the relative virtues of the two approaches?

It is highly unlikely you are going to create any significant "memory bloat". Your code will likely be infinitesimal compared PHP's memory requirement.

I suggest 3 files, one with your configuration settings, so they are all in one place and easy to find and change, another file with your functions and the third file contains the code for handling the internet interface. Obviously, the interface file controls everything by calling various functions as needed.

Al.......

--- End Message ---
--- Begin Message ---
Hi, 

  Just went online and saw an SVG generated from Python, and wanted to
do the similar thing by loading the SVG into an PHP script. Here is the
script that I have: 

<?php
 
#Load the Map
$ourFileName= "USA_Counties_with_FIPS_and_names.svg";
$fh = fopen($ourFileName, "r") or die("Can't open file");
fclose($fh); 

?>

The problem is that my screen appears as blank even though I could open
up USA_Counties_with_FIPS_and_names.svg and see the entire US Map. Does
anyone know what I might have done wrong here? 

Thanks in advance. 

Alice
                                          
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141664/direct/01/


--- End Message ---
--- Begin Message ---
Hi, 

  Just went online and saw an SVG generated from Python, and wanted to
do the similar thing by loading the SVG into an PHP script. Here is the
script that I have: 

<?php
 
#Load the Map
$ourFileName= "USA_Counties_with_FIPS_and_names.svg";
$fh = fopen($ourFileName, "r") or die("Can't open file");
fclose($fh); 

?>

The problem is that my screen appears as blank even though I could open
up USA_Counties_with_FIPS_and_names.svg and see the entire US Map. Does
anyone know what I might have done wrong here? 

Thanks in advance. 

Alice
                                          
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141664/direct/01/


--- End Message ---
--- Begin Message ---
Hi, 

  Just went online and saw an SVG generated from Python, and wanted to
do the similar thing by loading the SVG into an PHP script. Here is the
script that I have: 

<?php
 
#Load the Map
$ourFileName= "USA_Counties_with_FIPS_and_names.svg";
$fh = fopen($ourFileName, "r") or die("Can't open file");
fclose($fh); 

?>

The problem is that my screen appears as blank even though I could open
up USA_Counties_with_FIPS_and_names.svg and see the entire US Map. Does
anyone know what I might have done wrong here? 

Thanks in advance. 

Alice
                                          
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141664/direct/01/


--- End Message ---
--- Begin Message ---
I move a number of sites from one server to another and one the one server we 
had php4 and now we have php5 and since then my server seems to hang every time 
there is a header, location redirect. Anyone have any ideas on how to resolve 
this? Is there something I can easily change in the php.ini file that will 
resolve this issue?

Thanks
~V


--- End Message ---

Reply via email to