[PHP] url rewritting in php5

2004-12-13 Thread elixon
Hello!
I'm solving one problem and I'd like to ask you for hints/advices or 
'RTFM at link' answers.

Problem is:
I need special type of URL to be 'rewritten' in the way how the Apache 
does the URL rewritting.

example:
fopen('chrome://myfile.txt', 'r');
to have be internaly resolved for eaxample as
fopen('/var/www/localhost/chrome/myfile.txt', 'r');
I know that there is the way how to register url wrapper in PHP5. It is 
the solution. But I do not need to implement whole API.

Is there way to do something like this?
class ChromeWrapper extends PHP_STD_FILE_WRAPPER {
function stream_open($path,$mode,$opts,$opened_path) {
  $path=str_replace('chrome://', '/var/www/localhost/chrome/', $path);
  parent::stream_open($path, $mode, $opts, $opened_path);
}
}
... simply implement easily only the path rewritting instead of 
implementing all the functions that are already done in built-in api.

Or is there some way how to register 'filter' that filters $path instead 
of the content?

Thank you for sharing your knowledge
Danny 'elixon' Sevcik
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Question on functions

2004-11-11 Thread elixon
I'm not certified expert ;-) but what I meant is
Do not use function that writes to the hardcoded global variables:
example:
function db() {
...
$GLOBALS['db']=x_open_something($GLOBALS['...'], ...);
...
}
This function is really... hm... not flexible enough ;-)
It can make the job done well but... what if you need to open second 
connection? What if you have news data stored on other server or in 
defferent database under diferent user/password? Hm. What you will do? 
You probably create function db2(), yes? And what if you need to read 
page hit statistic from another database? ... db3()? ... db4()? Do you 
see the problem?

'functions' are pieces of GENERIC code doing the same thing with 
different input and resulting in possible different output... What you 
typed was not GENERIC - it was really one-purpose code that didn't need 
to be placed in function at all... You could simply include content of 
db() into your log() method and result would be the same...

I recomend to go this way (I modified your code, I didn't test it so 
typos/mistakes can be there - just showing the idea)...

/* User Defined Variables */
$defined = array( host = localhost, user = user, pwd = 
password );
$defined2 = array( host = localhost2, user = user2, pwd = 
password2 );

logs(db($defined));
logsOnOtherMachine(db($defined2)); // Little bit more flexible so you 
can use it for other purposes as well

/* Database connection */
function db($cfg) {
 if( connection_status() != 0 ) {
  $db = @mysql_pconnect( $cfg['host'], $cfg['user'], $cfg['pwd']) or 
die('connection problem...');
 }
 return $db;
}

/* Logging function */
function logs($db) {
 global $defined;
 if (!$db) {
 trigger_error('Connection was not established!', E_USER_ERROR);
 return false;
 }
 $pagecount = 1;
 $tble = logs;
 $sql = @mysql_query( SELECT * FROM ..., $db ) or die( problem... );
 // your stuff...
}
function logsOnOtherMachine($db) {
...
}

And if you would be really trying to dig in... have a look at OOP 
implementation in PHP... After the beginner's pain you will love it ;-)

Hope I helped little.
elixon
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] RDF/XML Parser: SimpleRDF

2004-11-10 Thread elixon
Hi all,
I was looking for an easy RDF parser writen in PHP but I failed. There 
are some parsers out there but I could not find the right one for me...

I decided to write an RDF parser by myself... not easy ;-)...
I created SimpleRDF parser on sourceforge.net under BSD license and I'd 
like to ask you guys for help.

If you have time to play little bit with RDF or you are looking for 
RDF/PHP parser - test mine (even if you don't expect to use it - just 
try it, please). I'm currently working on version 0.2 that has the 
ability to save (for now it can only read/parse and save N-Triples) 
RDF/XML documents.

SimpleRDF is based on PHP5/XSL. XSL part simplifies the RDF/XML source 
to allow easy parsing (XSL part can be used as standalone XSL stylesheet 
if you need). PHP5 part provides really simple API - my goal was really 
KISS (keep it simple, stupid). It is well commented.

Thanks for any testing/feedback...
Link: sf.net/projects/simplerdf
elixon
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Question on functions

2004-11-10 Thread elixon
Or you can use superglobal variable $GLOBALS that is array containing 
all GLOBAL variables. This variable is superglobal thus does not need to 
be declared global using 'global $GLOBALS;' statement. Works anywhere.

function database() {
... $GLOBALS['array'][0], $GLOBALS['array'][1] ...
}
elixon
Tip: I recommend to not use GLOBALS for this type of data. Better use 
function parameters - function database($host, $user, $pwd, $db) {...} 
It will save you time when your application grows and starts clashing 
with other global variables or third party pieces of code ;-)

Jason Gerfen wrote:
John Holmes wrote:
Jason wrote:
My question is in regard to passing global variables to a function. 
Here is my code, any idea why it is not working?  I suppose my 
understanding of a global variable being able to be used within a 
function is off?

global $array = array( 0 = hostname, 1 = username, 2 = 
password );

function database()
{

You need to declare it global within the function...
function database()
{
  global $array;
  ...
thanks, it figures it is something easy like that... =)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Multiple session_start()s / Is it a problem??

2004-11-10 Thread elixon
I guess that session_id() method will return null if session is not 
started (not tested) so theoreticaly you can use:

if (!session_id()) session_start();
elixon
Al wrote:
Is there a problem issuing multiple session_start()s for a given script?
I can't find anything in the manual that says one way or the other.
I have some scripts that call more than one functions include file and 
for convenience put a session_start() on each one.

This gives me a Notice error.
Of course I can simply use @session_start() to negate the Notice; but, 
I want to be certain this is good practice.

Al.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Multiple session_start()s / Is it a problem??

2004-11-10 Thread elixon
And I think that $_SESSION does not exist unless session is started =
if (!is_array($_SESSION)) session_start();
might do the job as well.
elixon
Al wrote:
Is there a problem issuing multiple session_start()s for a given script?
I can't find anything in the manual that says one way or the other.
I have some scripts that call more than one functions include file and 
for convenience put a session_start() on each one.

This gives me a Notice error.
Of course I can simply use @session_start() to negate the Notice; but, 
I want to be certain this is good practice.

Al.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php