[PHP] HELP - fwrite(...PHP code...)

2002-09-12 Thread Hankley, Chip

I have an application where I need to write PHP code to a file that will be
used later...but it's not working the way I'd expect.

When I issue the following:

fwrite($fp, ? echo $LayerScale);

If $LayerScale is defined, then fwrite outputs the value of $LayerScale to
the target, NOT the string $LayerScale.

How can I overcome this?

Chip

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




RE: [PHP] whats wrong with this?

2002-08-28 Thread Hankley, Chip

you need to use == instead of =

== is used when comparing values (i.e. is this == to that)
= is used to set something's value (i.e. this = that)

-chip

-Original Message-
From: Chris Barnes [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 28, 2002 11:12 AM
To: Php-General (E-mail)
Subject: [PHP] whats wrong with this?


I just cant seem to work out why this doesn't work. My PHP book doesn't
explain if statements very well so i have no idea if i am breaking a rule.

$system_day = date(j);

for($day = 1; $day  32; $day++){
if($day = $system_day){
echo match!;
}

else{
echo no match;
}
}

the problem i am experiencing is that it seems the if statement is setting
the $day value to equal $system_day instead of comparing their values
if i add

echo Day:  . $day .  System_day:  . $system_day;

before and after the if statement then the first result is something like

Day: 1 System_day: 29

after the if statement has executed the result is

Day: 29 System_day: 29

so you see, instead of if comparing $day to $system_day it is making $day
equal to $system_day.

any ideas why and how to fix this?

help is most appreciated :)


-- 
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] Building a query on multiple variables, how to test for which variables are valid?

2002-08-28 Thread Hankley, Chip

Jay -

How 'bout this?

$init = 1;
$query = SELECT foo ;
$query .= FROM bar WHERE;
if ($init AND isset($var1)) {
  $query .= WHERE thus = ' . $var1 . ' ;
  $init = 0;}

if ($init AND isset($var2)) {
  $query .= WHERE thus = ' . $var2 . ' ;
  $init = 0;}
elseif (isset($var2)) {
  $query .= AND WHERE thus = ' . $var2 . ' ;
  $init = 0;}  

if ($init AND isset($var3)) {
  $query .= WHERE thus = ' . $var3 . ' ;
  $init = 0;}
elseif (isset($var3)) {
  $query .= AND WHERE thus = ' . $var3 . ' ;
  $init = 0;}

if ($init AND isset($var4)) {
  $query .= WHERE thus = ' . $var4 . ' ;
  $init = 0;}
elseif (isset($var4)) {
  $query .= AND WHERE thus = ' . $var4 . ' ;
  $init = 0;}

... you could even make all of those if...elseif's into a function.

Chip

-Original Message-
From: Jay Blanchard [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 28, 2002 1:51 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Building a query on multiple variables, how to test for
which variables are valid?


So these 4 variables walk into a bar :^]

I have a form with 4 drop downs. Each of these drop downs might have a value
and there is no order in which they might have a value. A query needs to
built (the WHERE and AND portions) that takes into account which ever
variables have been set. A user may choose a variable that would not be in
the first location.

$var1 = is not set
$var2 = is set
$var3 = is set
$var4 = is not set

(or any other combination) The query, of course, needs to be in order taking
into account the above example;

$query = SELECT foo ;
$query .= FROM bar ;
$query .= WHERE thus = ' . $var2 . ' ;
$query .= AND thus = ' . $var3 . ' ;

If three of the variables are set then there would need to be an additional
AND statement, etc. It would be foolhardy to construct an if or case
statement that would take into account each possible combination. I have
been thinking this through for an hour or so, but I am not seeing a clear,
elegant, and efficient piece of code. Has anyone done anything like this, or
does anyone have an idea of how this might be done?

TIA!

Jay

*
* Texas PHP Developers Conf  Spring 2003*
* T Bar M Resort  Conference Center*
* New Braunfels, Texas  *
* Contact [EMAIL PROTECTED]   *
*   *
* Want to present a paper or workshop? Contact now! *
*



-- 
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] Re: Automatic Download using URL, HELP!

2002-08-26 Thread Hankley, Chip

Bogdan - 

Sorry for the delay to your follow-up.

The total script is below... first let me explain a little more of what I'm
doing for clarity's sake.

I'm downloading a lot of data files from a site. The way the site works, you
supply some information in a form regarding the data set you want. This goes
to a PERL script which creates a packaged (zipped) data set and puts it in
an FTP directory.

What I wanted to do was write a script that would automatically do the form
submission, retrieve the name and location of the zip file, and save it to
my local hard disk. I happened to have a list of over 1000 data set names
that I wanted to get... so I just needed to loop through them.

FWIW, the faking a form post part of this, which is really the core of
what I'm doing, is based on the following in the pgp_general archives:

  http://marc.theaimsgroup.com/?l=php-generalm=101899239727991w=2

You can search for this by searching the archives for the term asphttp.
ASPHTTP is a tool for ASP that does the same thing... only it costs money,
and this little function is free! How cool is that?

Here's the script (got it working, BTW).

Chip

?
/*--- PHP Script --*/
$data = array(dataset1, dataset2, ... , dataset1000);

//Loop through each value in the array, POSTING data, and downloading
// the dataset to the hard drive.
foreach($data as $a) {
  //Since this script is going to take a long time to execute
  // we need to set the max time limit to some really high 
  // number so that it doesn't time out. This probably needs
  // to be done on the web_server as well (e.g. the def time-out
  // in IIS is 300 seconds).
  set_time_limit(12);

  //The next two variables make up the location of the resource
  // that you will be posting to. This is basically what would
  // appear in the ACTION section of a FORM element. In this case:
  //  http://www.someserver.com/cgi-bin/some_script.pl
  $host=www.someserver.com;
  $path=/cgi-bin/some_script.pl;

  //The next line makes up the 'data to send' in the form. Apparently
  // if you start the string with a , this will use the POST method,
  // while if you start with a ? it will use the GET method (or at
  // least it's acting like it's doing one or the other).
  $data_to_send = myDataSetName= . $a .
FormVar1=Value1FormVar2=Value2;
  PostToHost($host, $path, $data_to_send);
}

function PostToHost($host, $path, $data_to_send)
{
  //This part of the function creates a file that essentially POSTs the
  // $data_to_send information to the $host . $path location, and retrieves
  // the information into a variable called $returnData
  $returnData=;
  $fp = fsockopen($host,80);
  fputs($fp, POST $path HTTP/1.1\n);
  fputs($fp, Host: $host\n);
  fputs($fp, Content-type: application/x-www-form-urlencoded\n);
  fputs($fp, Content-length: .strlen($data_to_send).\n);
  fputs($fp, Connection: close\n\n);
  fputs($fp, $data_to_send);

  //Loop through the variable $returnData line-by-line. In this case,
  // I'm searching for a keyword. The name of the resulting file is always
  // on a line like this:
  //  YOURFTPFILENAME = some_file_name_.
  //Once I hit this line, I want to save the entire line into a variable
  // called $filename, and break out of the loop.
  while(!feof($fp)) {
$returnData=fgets($fp, 128);
$filename = strstr($returnData, 'YOURFTPFILENAME');
if ($filename)
  break;
  }

  //Use some simple string parsing functions to strip out the
YOURFTPFILENAME = 
  // part of the filename.
  $filename = substr($filename, 18);
  $filename = trim($filename);

  //Now, I'm going to connect to and read the file that was created. In this
case
  // it is always saved to the same location, so all I need to do is specify
the
  // file name. The file will be read into a variable called $contents.
  $host = http://www.someserver.com/ftp_downloads/images/;;
  $fp2 = fopen($host . $filename, rb+);
  $contents = fread ($fp2, 2500); //use some rediculously large number
in fread
  // to ensure that you get the whole
thing.

  //make a file to write to on the local system, and dump $contents into the
new
  // file.
  $fp3 = fopen(D:\\myFiles\\SomeDirectory\\ . $filename, w);
  fputs($fp3, $contents);

  //close all of the documents
  fclose($fp);
  fclose($fp2);
  fclose($fp3);
}
/* End of Script ---*/
?

 -Original Message-
 From: Bogdan Stancescu [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, August 22, 2002 10:29 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Re: Automatic Download using URL, HELP!
 
 
 Just out of curiousity, how did you ever get PHP to prompt you where to 
 save a file? Could you post a more complete code sample?
 
 Bogdan

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




[PHP] ODBC to MS-Access View?

2001-07-13 Thread Hankley, Chip

I'm trying to connect up w/ an Access database one of our db administrators
set up.

The Access file has an adp extension...the data is housed in a view,
(essentially a read-only dump of some MS SQL Server tables).

I've set up the file as a System DSN in ODBC (WinNT)

When I issue the following command:

  $conn_id = odbc_connect($db, $username, $password) or die();

I get the following error:

Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] The Microsoft
Jet database engine cannot open the file '(unknown)'. It is already opened
exclusively by another user, or you need permission to view its data., SQL
state S1000 in SQLConnect in C:\Inetpub\wwwroot/seating/sharondb.php on line
36

Any ideas? I am supplying the correct username and password...

Thanks

Chip Hankley

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Security of PHP code

2001-07-04 Thread Hankley, Chip

OK,

I'm pretty new to PHP, and have been reading this thread, and am just a
little freaked.

If I understand this right, the only way reason we can view the source code
of those pages is that the web server on which the page resides essentially
has a PHP page somewhere on their site that has some variation of:

?show_source($file);?

as it's content, right?

While I can see the utility of that for some situations
(teaching...examples, etc.), it seems like a huge potential for security
breaches.

Is it possible to have such a function on your site w/o giving access to ALL
of your documents...

Chip

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]