pretty new to php and i think i might be missing some fundamental limitation of isset. i have two php scripts below that are executed by crond, one using --host X and one that does not. and below that are three different attempts at generating a command line that will be executed. the first example using strlen works as expected. please see bottom of thread for the command line that is generated for each php script respectively. when i came across isset it seemed to make more sense to use that instead, especially the third example. HOWEVER, both isset examples fail when $server is the value for -host. as you might guess -host is $host, --server is $server and --path is $path. is this an issue of having $server twice on the same line when using isset? i've been tinkering with this off and on for a few days and i'm stumped. i need not be spoon fed but some plain speak on what i might be misunderstanding would be great, thanks.
when using strlen example:
when using either isset example:
How do you set $host? Do you assume $host is automatically set by appending --host=$host to your php-program-call? If that is so: That's not happening - you have to parse command line args. Or did you just leave the command line parsing code out? If so, please show the code, how you parse the command line args.
First of all. There are functions and libs for everything. Command-Line-Option Parsing may be done with getopt: Look here: PHP: getopt - Manual
(But you may ignore that, if your code works).
The following does not work:
If you decide to use #!, it has to be at the very beginning of the Script-File. Only then the kernel will read the following binary as interpreter for the actual file.
Further without testing the code myself, I suggest you test, if your Arg-parsing produces correct output. I suspect it may not fully work as expected and the values are not what you assume them to be. I suggest you insert some debug statements before+after Arg parsing like:
A logging function would help you to debug your code independently of the running environment(webserver or command line).
The above mentioned debug statements are easily usable with such a log function(print_r needs to be told, that it returns the formated dump data and so it does not print it to stdout itself).
PHP.net is a great and fabulous source of documentation for PHP. Nearly all functions documentation pages have directly attached real-life coding examples down at the bottom of each page.
before i posted my query i commented all the parsing, processing and db statements and simply put echoes at the bottom so it would print the ssh command and all of the variables i expected to get set. the variables were all set as expected and so was the ssh command when i use strlen to determine if the $host variable was set. however, when i use either of the isset chunks the $server after the -host argument is null but the $server after the ConnectTimeout=60 is okay. i just don't get why my isset chunks won't put $server in both places i expect it to be when $host is not set. so let me ask this, do the two isset pieces look okay? thanks.
finally figured this one out. if i delete or comment the line in the php script:
the code works as expected now. it finally sunk in after reading the isset documentation untold times that a NULL variable is still a set variable. so although i had not supplied the:
as a command line arg to the script it would not put the $server value there because i had set $host as NULL with the:
Hello,
This function was copied into my code, which was compiled without error/warning, but when executed there is always Segmentation fault at the end after the output (which seems correct!):
void get_hashes(unsigned int hash, unsigned char *in)
{
unsigned char *str = in;
int pos =... (7 Replies)
Hi! I've a C program as shown below..
The line numbers and the statements of the program are separated by a space..
1 #include<stdio.h>
2 char a,b,c;
3 float x,y,z;
4 int main()
5 {
6 int d,e,f;
7 // further declarations
8 // further declarations
9 /* body*/
10 }
11 void fun1()
12... (1 Reply)
Hello All,
I am getting this error while compiling my application on IBM AIX 5.3.
As I tried to define _XOPEN_SOURCE=500 in makefile, that didn't work.
Please help us to resolve the error. (0 Replies)
My OS (Debian) and gcc use the UTF-8 locale. This code says that the char size is 1 byte but the size of 'a' is really 4 bytes.
int main(void)
{
setlocale(LC_ALL, "en_US.UTF-8");
printf("Char size: %i\nSize of char 'a': %i\nSize of Euro sign '€': %i\nLength of Euro sign: %i\n",... (8 Replies)
Hi!
Some minutes ago I've posted a question related with sed regexps because I need to catch information sended with forms with GET action. This is the post: https://www.unix.com/shell-programming-scripting/127800-regular-expression-sed.html
But now I have a new question. Does cgi scripts have... (0 Replies)
I have been getting some flack recently for my use of strlen() and strnlen(). Honestly I have always just taken their functionality for granted as being the easiest way of getting the length of a string. Is it really so much better to do pointer arithmetic? What am I gaining besides more... (3 Replies)
In a declaration, I have:
const char comment_begin = "<!--";
const char comment_end = "-->";
const int comment_begin_len = strlen(comment_begin);
const int comment_end_len = strlen(comment_end);
When I compile, I get the warnings:
emhttpc.c:64: warning: initializer element is not... (10 Replies)
Hi all,
I have a perl script which declares two variables and calls another perl script which accesses those variables. But I am unable to access the variables in the called script. My script is as follows:
my $ENV{a}="20";
system("perl called.pl");
and my called.pl contains:
print... (3 Replies)
Hello,
Just a little problem with the ksh function : strlen
I want to use this function in this little ksh program :
while read line ; do
TOTO=$line
TOTONB=strlen($TOTO)
echo $TOTONB (3 Replies)
hello,
i have a problem with strlen. I have written this:
for(y=13,z=0; cInBuf!=' ';y++)
{
cBuf=cInBuf;
z++;
}
len = strlen(cBuf);
out=len/2;
fprintf(outfile,"F%i",out);
If strlen is e.g. 22, it write F22. I want to write F2F2.
How can i do this?... (5 Replies)