php-general Digest 12 Jan 2012 12:16:50 -0000 Issue 7646

Topics (messages 316256 through 316270):

differences in between these env. variables
        316256 by: Haluk Karamete
        316259 by: Matijn Woudt
        316261 by: tamouse mailing lists

Re: Curl problems
        316257 by: Matijn Woudt
        316258 by: Rick Dwyer
        316260 by: Matijn Woudt

reporting errors when $ sign is missing in front of a variable
        316262 by: Haluk Karamete
        316263 by: Tommy Pham
        316264 by: Haluk Karamete
        316269 by: marco.behnke.biz
        316270 by: Mihai Anghel

http_referer. what's wrong with that?
        316265 by: Haluk Karamete
        316266 by: Ross McKay
        316267 by: Matt Neimeyer
        316268 by: Ken Robinson

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 ---
I've grouped these env variables, each group returns the same values
is there a difference? which ones do you use? which ones should I not
use for the purposes listed below

group1
SCRIPT_FILENAME vs PATH_TRANSLATED
where both return D:\Hosting\5291100\html\directory\file.php
purpose: get the full file path to the php script



group2
REMOTE_ADDR vs REMOTE_HOST
where both return same IP
purpose: get the visitor's ip

group3
REQUEST_URI vs SCRIPT_NAME vs URL vs ORIG_PATH_INFO vs PHP_SELF
which all return  /directory/file.php
purpose: get the virtual url to the php script

--- End Message ---
--- Begin Message ---
On Thu, Jan 12, 2012 at 12:26 AM, Haluk Karamete
<halukkaram...@gmail.com> wrote:
> I've grouped these env variables, each group returns the same values
> is there a difference? which ones do you use? which ones should I not
> use for the purposes listed below
>
You can find the answers here:
http://nl3.php.net/manual/en/reserved.variables.server.php
I'll try to answer them in short

> group1
> SCRIPT_FILENAME vs PATH_TRANSLATED
> where both return D:\Hosting\5291100\html\directory\file.php
> purpose: get the full file path to the php script
>
SCRIPT_FILENAME can be a relative path, PATH_TRANSLATED is the full
path. This is only true if run from CLI.
On my Ubuntu box I don't even have PATH_TRANSLATED, so SCRIPT_FILENAME
is recommended.
>
> group2
> REMOTE_ADDR vs REMOTE_HOST
> where both return same IP
> purpose: get the visitor's ip

REMOTE_HOST is not necessary always IP, if PHP succeeds to do a
reverse lookup (ie. get name for this ip), than REMOTE_HOST contains a
name instead of ip. You need to set a config option for this, though.
Recommended: REMOTE_ADDR, it matches what you need, doesn't need
config, and REMOTE_HOST doesn't even work for all hosts.
>
> group3
> REQUEST_URI vs SCRIPT_NAME vs URL vs ORIG_PATH_INFO vs PHP_SELF
> which all return  /directory/file.php
> purpose: get the virtual url to the php script

I'll extend your example. We now have a RewriteRule in apache like this:

RewriteRule ^files/?$ /directory/file.php [L,QSA]

Which will rewrite /files/... --> /directory/file.php

REQUEST_URI now contains how it was called by the browser,
'/files/something.php'
SCRIPT_NAME returns path to script (/directory/file.php), set by the
SAPI (apache, ..).
PHP_SELF returns also the path to script (/directory/file.php), but
set by PHP self.
I don't have any ORIG_PATH_INFO on my Ubuntu box, so be careful about this one.

Recommended: Depends on which you need. I prefer PHP_SELF over
SCRIPT_NAME, but that's more personal choice.

Matijn

--- End Message ---
--- Begin Message ---
On Wed, Jan 11, 2012 at 5:49 PM, Matijn Woudt <tijn...@gmail.com> wrote:
> On Thu, Jan 12, 2012 at 12:26 AM, Haluk Karamete
> <halukkaram...@gmail.com> wrote:
>> I've grouped these env variables, each group returns the same values
>> is there a difference? which ones do you use? which ones should I not
>> use for the purposes listed below
>>
> You can find the answers here:
> http://nl3.php.net/manual/en/reserved.variables.server.php
> I'll try to answer them in short
>
>> group1
>> SCRIPT_FILENAME vs PATH_TRANSLATED
>> where both return D:\Hosting\5291100\html\directory\file.php
>> purpose: get the full file path to the php script
>>
> SCRIPT_FILENAME can be a relative path, PATH_TRANSLATED is the full
> path. This is only true if run from CLI.
> On my Ubuntu box I don't even have PATH_TRANSLATED, so SCRIPT_FILENAME
> is recommended.
>>
>> group2
>> REMOTE_ADDR vs REMOTE_HOST
>> where both return same IP
>> purpose: get the visitor's ip
>
> REMOTE_HOST is not necessary always IP, if PHP succeeds to do a
> reverse lookup (ie. get name for this ip), than REMOTE_HOST contains a
> name instead of ip. You need to set a config option for this, though.
> Recommended: REMOTE_ADDR, it matches what you need, doesn't need
> config, and REMOTE_HOST doesn't even work for all hosts.
>>
>> group3
>> REQUEST_URI vs SCRIPT_NAME vs URL vs ORIG_PATH_INFO vs PHP_SELF
>> which all return  /directory/file.php
>> purpose: get the virtual url to the php script
>
> I'll extend your example. We now have a RewriteRule in apache like this:
>
> RewriteRule ^files/?$ /directory/file.php [L,QSA]
>
> Which will rewrite /files/... --> /directory/file.php
>
> REQUEST_URI now contains how it was called by the browser,
> '/files/something.php'
> SCRIPT_NAME returns path to script (/directory/file.php), set by the
> SAPI (apache, ..).
> PHP_SELF returns also the path to script (/directory/file.php), but
> set by PHP self.
> I don't have any ORIG_PATH_INFO on my Ubuntu box, so be careful about this 
> one.
>
> Recommended: Depends on which you need. I prefer PHP_SELF over
> SCRIPT_NAME, but that's more personal choice.
>
> Matijn
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Is there ever a case where SCRIPT_NAME does not equal PHP_SELF?

--- End Message ---
--- Begin Message ---
On Thu, Jan 12, 2012 at 12:20 AM, Rick Dwyer <rpdw...@earthlink.net> wrote:
> Hello all.
>
> I use curl to make a call to another page on my site... but it operates
> erroneously.... sometimes working... sometimes not.  The page it calls
> creates an email and I can see on the server the email in the queue when
> it's working.  If I echo out the URL the curl command is supposed to load
> and load it manually, it works without fail.
>
> Any help on what I am doing wrong below is greatly appreciated.
>
> Thanks.
>
>
> $curl_handle=curl_init();
> curl_setopt($curl_handle,CURLOPT_URL,'https://mydomain.com/email_confirmation.htm?id_order='.$id_order.'&sess_id='.$sess_id);
> curl_exec($curl_handle);
> curl_close($curl_handle);
>
>  --Rick

It's maybe not a real answer to your question, but if all you want to
do is call that page, why don't you just use
file_get_contents(https://mydomain.com/email_confirmation.htm?id_order='.$id_order.'&sess_id='.$sess_id);
(See [1])
It works out of the box, and I have found curl unstable too sometimes.

Matijn

[1] www.php.net/file_get_contents

--- End Message ---
--- Begin Message ---
On Jan 11, 2012, at 6:29 PM, Matijn Woudt wrote:

On Thu, Jan 12, 2012 at 12:20 AM, Rick Dwyer <rpdw...@earthlink.net> wrote:
Hello all.

I use curl to make a call to another page on my site... but it operates erroneously.... sometimes working... sometimes not. The page it calls creates an email and I can see on the server the email in the queue when it's working. If I echo out the URL the curl command is supposed to load
and load it manually, it works without fail.

Any help on what I am doing wrong below is greatly appreciated.

Thanks.


$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'https://mydomain.com/email_confirmation.htm?id_order='.$id_order.'&sess_id='.$sess_id) ;
curl_exec($curl_handle);
curl_close($curl_handle);

 --Rick

It's maybe not a real answer to your question, but if all you want to
do is call that page, why don't you just use
file_get_contents(https://mydomain.com/email_confirmation.htm?id_order='.$id_order.'&sess_id='.$sess_id );
(See [1])
It works out of the box, and I have found curl unstable too sometimes.

Matijn

Thanks Matijn,
But I get "Notice: file_get_contents() [function.file-get-contents]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?"... I'm using a hosting provider and I don't believe they will enable this for security reasons.

--Rick



--- End Message ---
--- Begin Message ---
On Thu, Jan 12, 2012 at 12:44 AM, Rick Dwyer <rpdw...@earthlink.net> wrote:
> On Jan 11, 2012, at 6:29 PM, Matijn Woudt wrote:
>
>> On Thu, Jan 12, 2012 at 12:20 AM, Rick Dwyer <rpdw...@earthlink.net>
>> wrote:
>>>
>>> Hello all.
>>>
>>> I use curl to make a call to another page on my site... but it operates
>>> erroneously.... sometimes working... sometimes not.  The page it calls
>>> creates an email and I can see on the server the email in the queue when
>>> it's working.  If I echo out the URL the curl command is supposed to load
>>> and load it manually, it works without fail.
>>>
>>> Any help on what I am doing wrong below is greatly appreciated.
>>>
>>> Thanks.
>>>
>>>
>>> $curl_handle=curl_init();
>>>
>>> curl_setopt($curl_handle,CURLOPT_URL,'https://mydomain.com/email_confirmation.htm?id_order='.$id_order.'&sess_id='.$sess_id);
>>> curl_exec($curl_handle);
>>> curl_close($curl_handle);
>>>
>>>  --Rick
>>
>>
>> It's maybe not a real answer to your question, but if all you want to
>> do is call that page, why don't you just use
>>
>> file_get_contents(https://mydomain.com/email_confirmation.htm?id_order='.$id_order.'&sess_id='.$sess_id);
>> (See [1])
>> It works out of the box, and I have found curl unstable too sometimes.
>>
>> Matijn
>
>
> Thanks Matijn,
> But I get "Notice: file_get_contents() [function.file-get-contents]: Unable
> to find the wrapper "https" - did you forget to enable it when you
> configured PHP?"... I'm using a hosting provider and I don't believe they
> will enable this for security reasons.
>
> --Rick

It seems like they have not compiled PHP with SSL support, or they're
using a pretty old version. Anyway, you're probably stuck with cURL
then, check the return of curl_exec, and if false, call curl_error to
get an error message.

Matijn

--- End Message ---
--- Begin Message ---
Hi, I'm coming from ASP background.
There, there is a life saver option called "option explicit". It
forces you to declare your variables using the "dim" statement. The
good thing about that is that if you were to mis-spell one of your
variables, asp.dll throws an error stating that on line so and so,
variable so and so not declared. This allows you to immediately fix
the error saving lots of time. If you did not use "option explicit",
then that misspelled variable would not have caused any error and you
woud have spent much more time debugging your app as to what went
wrong where.

Now, I undersand with PHP, that we do not have a variable declaration
per se; you put a $ sign in front of a word, and that becomes a
variable. Since in asp, we do not use $ much. I keep forgetting that.
I first declare a var and set a value for it using the $. But then I
refer to the darned thing, without the $. And there are no errors. Ths
behaviour seems extremely odd to me.

How do I achieve the functionality that if I forget to use $ sign for
a previously declared variable, php throws me an error.

example

$my_var = 90;
echo my_var;

I want an error to be thrown in line 2. what do I need to do?"
I was assuming  that since there is no function titled "my_var", PHP
would have complain right there and then. But instead, it simply
echoes "my_var".

I would have expected "my_var" to be outputted only if I were to write
echo "my_var";. This beats me.

At the top of my page, I already have this <?php error_reporting
(E_ALL ^ E_NOTICE); ?>

Haluk

--- End Message ---
--- Begin Message ---
On Wed, Jan 11, 2012 at 8:43 PM, Haluk Karamete <halukkaram...@gmail.com> wrote:
>
> Hi, I'm coming from ASP background.
> There, there is a life saver option called "option explicit". It
> forces you to declare your variables using the "dim" statement. The
> good thing about that is that if you were to mis-spell one of your
> variables, asp.dll throws an error stating that on line so and so,
> variable so and so not declared. This allows you to immediately fix
> the error saving lots of time. If you did not use "option explicit",
> then that misspelled variable would not have caused any error and you
> woud have spent much more time debugging your app as to what went
> wrong where.
>
> Now, I undersand with PHP, that we do not have a variable declaration
> per se; you put a $ sign in front of a word, and that becomes a
> variable. Since in asp, we do not use $ much. I keep forgetting that.
> I first declare a var and set a value for it using the $. But then I
> refer to the darned thing, without the $. And there are no errors. Ths
> behaviour seems extremely odd to me.
>
> How do I achieve the functionality that if I forget to use $ sign for
> a previously declared variable, php throws me an error.
>
> example
>
> $my_var = 90;
> echo my_var;
>
> I want an error to be thrown in line 2. what do I need to do?"
> I was assuming  that since there is no function titled "my_var", PHP
> would have complain right there and then. But instead, it simply
> echoes "my_var".
>
> I would have expected "my_var" to be outputted only if I were to write
> echo "my_var";. This beats me.
>
> At the top of my page, I already have this <?php error_reporting
> (E_ALL ^ E_NOTICE); ?>
>
> Haluk
>
>

This works for me in development environment without a debugger setup
using a web browser (note that I'm using 5.4RC2 so the default
behavior of error_reporting(E_ALL) is different [1]:

Notice: Use of undefined constant my_var - assumed 'my_var' in
F:\dev\sites\wwwroot\php_apps\test.php on line 5
my_var <?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
$my_var = 90;
echo my_var;

highlight_file(__FILE__);

Good luck,
Tommy

[1] http://php.net/function.error-reporting

--- End Message ---
--- Begin Message ---
Thanks...
Well I just changed the <?php error_reporting (E_ALL ^ E_NOTICE); ?>
 to <?php error_reporting (E_ALL ); ?>  and that does it for me.

Notice: Use of undefined constant my_age - assumed 'my_age' in
D:\Hosting\5291100\html\blueprint\bp_library.php on line 40
my_age

Now back in business :)


Notice: Use of undefined constant my_age - assumed 'my_age' in
D:\Hosting\5291100\html\blueprint\bp_library.php on line 40my_age
On Wed, Jan 11, 2012 at 9:12 PM, Tommy Pham <tommy...@gmail.com> wrote:
> On Wed, Jan 11, 2012 at 8:43 PM, Haluk Karamete <halukkaram...@gmail.com> 
> wrote:
>>
>> Hi, I'm coming from ASP background.
>> There, there is a life saver option called "option explicit". It
>> forces you to declare your variables using the "dim" statement. The
>> good thing about that is that if you were to mis-spell one of your
>> variables, asp.dll throws an error stating that on line so and so,
>> variable so and so not declared. This allows you to immediately fix
>> the error saving lots of time. If you did not use "option explicit",
>> then that misspelled variable would not have caused any error and you
>> woud have spent much more time debugging your app as to what went
>> wrong where.
>>
>> Now, I undersand with PHP, that we do not have a variable declaration
>> per se; you put a $ sign in front of a word, and that becomes a
>> variable. Since in asp, we do not use $ much. I keep forgetting that.
>> I first declare a var and set a value for it using the $. But then I
>> refer to the darned thing, without the $. And there are no errors. Ths
>> behaviour seems extremely odd to me.
>>
>> How do I achieve the functionality that if I forget to use $ sign for
>> a previously declared variable, php throws me an error.
>>
>> example
>>
>> $my_var = 90;
>> echo my_var;
>>
>> I want an error to be thrown in line 2. what do I need to do?"
>> I was assuming  that since there is no function titled "my_var", PHP
>> would have complain right there and then. But instead, it simply
>> echoes "my_var".
>>
>> I would have expected "my_var" to be outputted only if I were to write
>> echo "my_var";. This beats me.
>>
>> At the top of my page, I already have this <?php error_reporting
>> (E_ALL ^ E_NOTICE); ?>
>>
>> Haluk
>>
>>
>
> This works for me in development environment without a debugger setup
> using a web browser (note that I'm using 5.4RC2 so the default
> behavior of error_reporting(E_ALL) is different [1]:
>
> Notice: Use of undefined constant my_var - assumed 'my_var' in
> F:\dev\sites\wwwroot\php_apps\test.php on line 5
> my_var <?php
> error_reporting(E_ALL);
> ini_set('display_errors', 'on');
> $my_var = 90;
> echo my_var;
>
> highlight_file(__FILE__);
>
> Good luck,
> Tommy
>
> [1] http://php.net/function.error-reporting

--- End Message ---
--- Begin Message ---
 
Haluk Karamete <halukkaram...@gmail.com> hat am 12. Januar 2012 um 06:17
geschrieben:

> Thanks...
> Well I just changed the <?php error_reporting (E_ALL ^ E_NOTICE); ?>
>  to <?php error_reporting (E_ALL ); ?>  and that does it for me.
>
> Notice: Use of undefined constant my_age - assumed 'my_age' in
> D:\Hosting\5291100\html\blueprint\bp_library.php on line 40
> my_age
>
> Now back in business :)
 
If you are programming with an IDE, it does the work for you. While programming
you will see warning notices, that you are refering to something unknown.
 

--- End Message ---
--- Begin Message ---
Also, you get the output "my_var" because if you say echo my_var PHP
looks for a constant my_var and if it doesn't find one it just assumes
you want the name of the constant.Look in the manual page for
constants for more details about how they work
http://php.net/manual/en/language.constants.php

On Thu, Jan 12, 2012 at 9:57 AM, ma...@behnke.biz <ma...@behnke.biz> wrote:
>
> Haluk Karamete <halukkaram...@gmail.com> hat am 12. Januar 2012 um 06:17
> geschrieben:
>
>> Thanks...
>> Well I just changed the <?php error_reporting (E_ALL ^ E_NOTICE); ?>
>>  to <?php error_reporting (E_ALL ); ?>  and that does it for me.
>>
>> Notice: Use of undefined constant my_age - assumed 'my_age' in
>> D:\Hosting\5291100\html\blueprint\bp_library.php on line 40
>> my_age
>>
>> Now back in business :)
>
> If you are programming with an IDE, it does the work for you. While 
> programming
> you will see warning notices, that you are refering to something unknown.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
Because I got this

echo $_SERVER['HTTP_REFERER'];

I end up with this

Notice: Undefined index: HTTP_REFERER in
D:\Hosting\5291100\html\blueprint\bp_library.php on line 16
die;

Now, this is of course after the <?php error_reporting (E_ALL); ?>  change.

One solution is to dodge it by

echo @$_SERVER['HTTP_REFERER'];

But I'm still curious, what configuration am I missing so that
http_referer is treated like that?

--- End Message ---
--- Begin Message ---
On Wed, 11 Jan 2012 21:27:58 -0800, Haluk Karamete wrote:

>[...]
>Notice: Undefined index: HTTP_REFERER in
>D:\Hosting\5291100\html\blueprint\bp_library.php on line 16
>die;
>[...]
>But I'm still curious, what configuration am I missing so that
>http_referer is treated like that?

You only get an HTTP_REFERER when you link to a page from another page.
If you go directly to the page, e.g. by typing / pasting the URL into
the location bar, or linking from an email, then there is no
HTTP_REFERER.
-- 
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin

--- End Message ---
--- Begin Message ---
While perhaps unlikely in "common users" it is also possible to
prevent your browser from sending the referrer. IIRC, the referrer can
also get mangled when passing through HTTPS (although I don't remember
on which side, HTTP->HTTPS or HTTPS->HTTP or both)

Matt

On Thu, Jan 12, 2012 at 1:11 AM, Ross McKay <ro...@zeta.org.au> wrote:
> On Wed, 11 Jan 2012 21:27:58 -0800, Haluk Karamete wrote:
>
>>[...]
>>Notice: Undefined index: HTTP_REFERER in
>>D:\Hosting\5291100\html\blueprint\bp_library.php on line 16
>>die;
>>[...]
>>But I'm still curious, what configuration am I missing so that
>>http_referer is treated like that?
>
> You only get an HTTP_REFERER when you link to a page from another page.
> If you go directly to the page, e.g. by typing / pasting the URL into
> the location bar, or linking from an email, then there is no
> HTTP_REFERER.
> --
> Ross McKay, Toronto, NSW Australia
> "Let the laddie play wi the knife - he'll learn"
> - The Wee Book of Calvin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
At 12:27 AM 1/12/2012, Haluk Karamete wrote:
Because I got this

echo $_SERVER['HTTP_REFERER'];

I end up with this

Notice: Undefined index: HTTP_REFERER in
D:\Hosting\5291100\html\blueprint\bp_library.php on line 16
die;

Now, this is of course after the <?php error_reporting (E_ALL); ?>  change.

One solution is to dodge it by

echo @$_SERVER['HTTP_REFERER'];

The better way to avoid the error is to do something like

echo (isset($_SERVER['HTTP_REFERER']))?$_SERVER['HTTP_REFERER']:'No referrer set';

Which checks to see if it's set before echoing the value. If it's not set, you get a message saying so.

Ken



--- End Message ---

Reply via email to