Showing posts with label TipsPHP. Show all posts
Showing posts with label TipsPHP. Show all posts

Thursday, December 28, 2006

Installing PHP as CGI on Cygwin

For days of struggling to make PHP work on the Cygwin, I finally figure it out. I've installed Cygwin few years ago and apparently I've tried to install PHP on Cygwin before. Some of my left over setting on httpd.conf was screwing me over and over again for last few days. Here is the left over code:

AddHandler cgi-script .cgi .pl .php

It actually try to run .php file directly, not invoking PHP program. It gave me strange error on /var/log/apache/error_log that

line 1: ?php: No such file or directory

After removing .php extension on AddHandler, I've create php-cgi on /cgi-bin/ directory

#!/bin/sh
export PATH="/bin:$PATH"
win_page=`cygpath -w "$PATH_TRANSLATED"`
export PATH_TRANSLATED="$win_page"
php 2>&1

Found on www.cygwin.com/ml/cygwin/2002-05/msg00591.html via Google Cache. And added following line on httpd.conf file

AddType application/x-httpd-php .php
Action application/x-httpd-php "/cgi-bin/php-cgi"

Tuesday, December 19, 2006

How to use PHP Session.

Start with start_session() command. It needs to be include on every PHP page that will use session. You can pass the variables between PHP pages using the global $_SESSION variable. When you are done with the session, unset the $_SESSION variable and call session_destroy() command.

page1.php
<?php
start_session();
$_SESSION['valid_user'] = 'Me';
?>

page2.php
<?php
start_session();
if ( isset($_SESSION['valid_user'] ) {
print 'hello ' . $_SESSION['valid_user'];
} else {
print 'hello nobody';
}
// close session
// don't do this: $_SESSION = array();
unset($_SESSION['valid_user'];
session_destroy();
}
?>