Gentlemen,
First, I appreciate your comments.
I have successfully tested a PHP style CGI and called it from the Shopsite
Order API folder.
I have encountered another hurdle and I have found a workaround, but I am
not sure if this is such a good idea!
Essentially, my Session Variables are lost when my script is called
automatically from Shopsite. I have done lots of research on this and see
it is a problem, which other people have faced. In case you are wondering,
I am calling the start_session() function at the top of my script. The
problem is when I check the session id, it is a completely new session and
none of the session variables contain the data I defined when the user
logged into my site.
One possible reason for this issue is reported in the following link -
http://support.microsoft.com/default.as ... -us;316112and summarized here - "Security patch MS01-055 prevents servers with
improper name syntax from setting cookies names. Domains that use cookies
must use only alphanumeric characters ("-" or ".") in the domain name and
the server name. Internet Explorer blocks cookies from a server if the
server name contains other characters, such as an underscore character
("_")." Since there are lots of strange characters in some of the
Shopsite generated pages, I am not sure if this is contributing to the
problem or if the automatic order API call somehow trashes the session.
My initial workaround - I capture the users IP address when they log into my
site and then store it in my database. When the user executes an order
through Shopsite, I have my script capture the IP address again, look
through the user table in my database for a matching IP. I then lookup the
associated user. This allows me to take the Shopsite purchase data for that
user and update the other tables, pages, etc. in my database.
I suspect that this is not the best solution and have the following
questions:
- Is it secure?
- Does a user's IP address ever change in the middle of a connection?
- If the connection drops for some reason and they reconnect, does the IP
address typically change? I understand some ISPs dynamically assign them,
so this might be a problem.
- Would it be feasible to add error trapping code in my script so a changed
IP address is detected (when it sees that there is no matching IP) and the
customer/webmaster is then notified that the necessary updates will have to
be processed manually? It will be a minor inconvenience, but not too bad if
it doesn't happen regularly. This manual processing will be necessary since
the purchase was completed prior to the cgi call.
If this is not a feasible option and I can't figure out how to get the
sessions working, I might have to log in again after they make the purchase
(but that wouldn't be a very user friendly option, of course).
Any advice you can provide would be appreciated!
Thank you.
Tom Mitoraj
"Brandon Eley" <brandon@2bigfeet.com> wrote in message
news:cdmk9e$j1g$2@eval.shopsite.com...
It's probably a good idea just out of practice (and easy updating) to
name files according to what they do. Naming a php file *.pl or *.cgi
just seems confusing especially if you are not the only person that will
ever work on the site...
Brandon Eley
2BigFeet.com
brandon@2bigfeet.comwww.2bigfeet.comLoren wrote:
PHP can be used as a shell scripting language like Perl, however it is
not compiled that way by default on most systems.
On UNIX systems it does not matter if an executable is named .cgi, .pl,
.php, or whatever. If the file is executable and is in a directory where
direct execution is allow (for example, in a cgi-bin directory or in the
ShopSite cgi directories), the system will check to see if it is a
binary file or a text file. If it is a binary file, if will try to
execute it directly, if it is a text file is will look for the
#!/path/to/shell/interpreter line on the first line of the file. So in
theory you can have a PHP script executed that way (#!/usr/bin/php, or
whatever), however unless you specifically know that PHP interpreter
binary was compiled to allow CGI-type execution, you can almost bet that
it was not.
When accessing PHP files directly (by URL), then they do need to be
named .php (or .php3, or .phtml), because in that case the webserver is
loading them through it's PHP module, so it needs to see those
extensions. PHP files accessed this way do not need the execute
permission bit set, but ones that are run as CGI's (see paragraph above)
do.
-Loren
Brandon Eley wrote:
I have some observations... first is that PHP is not CGI. You do not
need to, nor should you, put PHP scripts in your CGI-BIN or name them
*.pl or *.cgi. CGI-BIN is for executable CGI and PERL scripts. PHP is
a completely different scripting language (though very similar) and
thus should not be named *.pl or *.cgi but only *.php, *.php4 or
*.php3 (for version numbers) or *.phtml (if your server is setup this
way - rare though).
By naming a PHP script *.cgi or *.pl you are telling the web server to
treat the file as a CGI or perl script which will change what it
executes. Since the languages are different, you are not getting the
same results.
If you need a cgi script (i.e. for order api) make sure it is written
in perl, not PHP. Then you can name it .cgi or .pl and place it inside
your CGI-BIN and it will execute correctly.
Otherwise just leave the file in your htdocs or public_html directory
named *.php and execute it from there.
Hope this helps...
Brandon Eley
2BigFeet.com
brandon@2bigfeet.comwww.2bigfeet.comtjmitoraj wrote:
I am creating a a cgi script using PHP.
In my initial test script, the basic purpose is to capture a user's
member
id from the session.
I have a very basic test script (test.php) which works fine when I
access it
with my browser. The php file is stored in my htdocs folder.
However, when I store it in the shopsite cgi-bin, rename it to
test.cgi and
make a test purchase, I get the following error:
Warning: session_start(): Cannot send session cookie - headers
already sent
by (output started at /usr/local/apache/cgi-bin/sc/test.cgi:3) in
/usr/local/apache/cgi-bin/sc/test.cgi on line 4
I have researched this on the web and see this error is common. The
most
common advice is to search for blank space at the beginning or end of
the
file. Checked that and I don't have any.
The other advice I see is to check the permissions and ownership of
the
file. I am not positive what it should be set to, but I checked the
customdump.cgi file and see it was set to www/webadmin and 0755.
Still get
same error.
If it helps, here are the first few lines of my code: There is no
space at
the top of my file.
#!/usr/local/bin/php
?
session_start();
include "verify.inc";
?
html
head
/head
body
By the way, when I tried to delete the line between
#!/usr/local/bin/php and
?, I get another error message:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable
to complete your request.
Any ideas on how I can resolve this situation would be appreciated.
Thank you.
Tom Mitoraj