Gui Guan’s BLOG

There’s more than one way to do it

Archive for the ‘PHP’ Category

Today, when I was reviewing the session part of PHP, I suddenly came out a question: how to make PHP to append session ID(SID) to your page links automatically when cookies are forbidden in that browser? I managed to do this in JSP, but not sure whether the PHP can also handle this problem.

I checked the configuration files (php.ini) for my apache server, and there is a session section, under which there is a setting session.use_trans_sid = 0. After I changed this to session.use_trans_sid = 1, and restarted apache, the links of the page which invoked session_start() have now appended the SID. There is also an url_rewriter.tags, with which you can define what elements of a page will be appended.

Here are some demo codes:

sessions.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php ob_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<title>Untitled</title>
</head>
 
<body>
<?php
	ini_set('session.use_trans_sid','1'); //you can also do this instead of modify php.ini
	session_start();
	$_SESSION['test']='right!';
	//header('Location: sessions2.php'); //SID won't be appended in this situation
	//exit();
?>
<a href="sessions2.php">click here</a>
</body>
</html>
<?php ob_end_flush(); ?>

sessions2.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php ob_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<title>Untitled</title>
</head>
 
<body>
<?php
	session_start();
	echo $_SESSION['test'];
?>
 
</body>
</html>
<?php ob_end_flush(); ?>
  • 1 Comment
  • Filed under: PHP
  • Gui Guan’s Laboratory

    Gui Guan’s Laboratory
    There’s more than one way to do it

    Gui Guan's Laboratory Logo

    http://lab.guiguan.net

    发现Bluehost的服务器环境非常适合在学校和家里来测试PHP脚本,呵呵。同时为了更好的学习Internet Computing,弄了一个自己的实验室,有点Google’s Lab的感觉,但是差远老:P lol

    当你点击进入之后,便是我完成的IC的第二次作业啦(默认用户名:user 密码:password)。以下是这次作业的一些要点:

    • sticky form
    • input validation
    • POST
    • SESSION
    • mail

    (待续…)

  • 0 Comments
  • Filed under: Life, PHP, Website Log
  • Zend Debugger 5.2.5 and Zend Studio 5.5 are both newest products from Zend, the PHP company. Zend Debugger is a full-featured server side php debugger engine, an interactive tool that helps you debug PHP scripts. Zend Studio is a fantastic IDE for PHP programming(I am really happy with its code assistant). If they work together, we can use them to debug any PHP codes on a web server,  and have a good studying and development enviroment of PHP.

    The installation of Zend Studio 5.5 is very easy. Just follow its setup sequence. However, the installation and configuration for Zend Debugger 5.2.5 is demanding. Fortunately, we have a really good tutorial here. Following its steps start from "Find the extension directory" and you will have this image from call phpinfo() method which indicate the successful of installation.

    If you can’t get Zend Debugger to work although you have followed instruction of that tutorial. Please try following solution:

    1. open your php.ini (you can find it by calling phpinfo() method and looking up the "Configuration File (php.ini) Path" entry (more…)
  • 2 Comments
  • Filed under: PHP