[PHP] How can I tell if a path is absolute?
Hi! I used to detect whether a path is absolute by seeing if the first character is a forward slash. Unfortunately, Windows absolute paths are in a different syntax like C:\, and I don't know what other random systems might have for their syntax in the future. So, is there a portable way to tell if a path is absolute or not? I thought about comparing the start of the path with realpath('/'), but this only works if the path starts with C: and fails for D: and other drives. TX -- 'Every sufficiently advanced technology is indistinguishable from magic' - Arthur C Clarke 'Every sufficiently advanced magic is indistinguishable from technology' - Tom Graves Email: Trejkaz Xaoza [EMAIL PROTECTED] Web site: http://xaoza.net/trejkaz/ Jabber ID: [EMAIL PROTECTED] GPG Fingerprint: 9EEB 97D7 8F7B 7977 F39F A62C B8C7 BC8B 037E EA73 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How can I tell if a path is absolute?
Michael Ochs wrote: Hi, maybe you could try it with regular expressions! [A-Z]:\\ or better [C-Z]:\\ because A and B is used just for floppy drives... Take a look at www.php.net/preg_match/ I'm not sure if you noticed, but I said I wanted it to be portable. Sure, ([A-Za-z]:)?[/\\] would work to some extent, but would it work perfectly? As far as I can tell, the path C:/ is _relative_ on Linux and BSD. Am I wrong? TX -- 'Every sufficiently advanced technology is indistinguishable from magic' - Arthur C Clarke 'Every sufficiently advanced magic is indistinguishable from technology' - Tom Graves Email: Trejkaz Xaoza [EMAIL PROTECTED] Web site: http://xaoza.net/trejkaz/ Jabber ID: [EMAIL PROTECTED] GPG Fingerprint: 9EEB 97D7 8F7B 7977 F39F A62C B8C7 BC8B 037E EA73 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How can I tell if a path is absolute?
Tularis wrote: c:/ wouldn't even work as a path on unix systems. [134] [EMAIL PROTECTED]:/tmp mkdir c: [135] [EMAIL PROTECTED]:/tmp ls -la c:/ total 8 drwxr-xr-x 2 trejkaz users 4096 Jul 17 21:01 . drwxrwxrwt 52 rootroot 4096 Jul 17 21:01 .. You were saying? Anyway it's looking a lot like I'll have to detect the Win32 build of PHP at runtime, and choose the method based on that. All because PHP doesn't have an is_absolute function or anything similarly convenient. :-/ TX -- 'Every sufficiently advanced technology is indistinguishable from magic' - Arthur C Clarke 'Every sufficiently advanced magic is indistinguishable from technology' - Tom Graves Email: Trejkaz Xaoza [EMAIL PROTECTED] Web site: http://xaoza.net/trejkaz/ Jabber ID: [EMAIL PROTECTED] GPG Fingerprint: 9EEB 97D7 8F7B 7977 F39F A62C B8C7 BC8B 037E EA73 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How can I tell if a path is absolute?
Jason Barnett wrote: A, methinks I have a competitor for a FileSystem Manager :) Perhaps I misunderstand your problem, but this works fine for me (WinXP) because realpath [quote]Returns canonicalized absolute pathname[/quote]: ?php // we know __FILE__ is an absolute path $file = __FILE__; echo realpath(__FILE__) == $file ? 'The same path' : 'Not the same path'; ? http://www.php.net/realpath That works because the value in __FILE__ seems to be both canonicalised and absolute. For an example which breaks, realpath('/home') on my server returns '/usr/home', so your example would claim that /home is not absolute. Yet, it is. :-/ TX -- 'Every sufficiently advanced technology is indistinguishable from magic' - Arthur C Clarke 'Every sufficiently advanced magic is indistinguishable from technology' - Tom Graves Email: Trejkaz Xaoza [EMAIL PROTECTED] Web site: http://xaoza.net/trejkaz/ Jabber ID: [EMAIL PROTECTED] GPG Fingerprint: 9EEB 97D7 8F7B 7977 F39F A62C B8C7 BC8B 037E EA73 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How can I tell if a path is absolute?
Curt Zirzow wrote: A simple workaround is testing OS: if (windows) // use realpath method } else { $absolute = $path{0} == '/'; } I don't know what the realpath method is since every one I've been given that involves realpath so far doesn't work. But here's what I'm doing now: function is_absolute($path) { $regex = (PHP_OS == 'WINNT' || PHP_OS == 'WIN32') ? /^([a-z][A-Z]:)?[\/\\]/ : /^\//; return (boolean) preg_match($regex, $path); } Does that look safe enough? It works for Linux but since I have no Windows environments to test on I have no idea if it works properly on Windows. TX -- 'Every sufficiently advanced technology is indistinguishable from magic' - Arthur C Clarke 'Every sufficiently advanced magic is indistinguishable from technology' - Tom Graves Email: Trejkaz Xaoza [EMAIL PROTECTED] Web site: http://xaoza.net/trejkaz/ Jabber ID: [EMAIL PROTECTED] GPG Fingerprint: 9EEB 97D7 8F7B 7977 F39F A62C B8C7 BC8B 037E EA73 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Emtying Variables
Php wrote: And you can also used a php variable to detect multiple submit: Even better would be using a token which you give to the user when the form is displayed. That way they can't accidentally submit the form on first entry to the site (and believe me, this can happen, because Konqueror occasionally remembers a form submission page was in its window the last time it was run, and tries to reload the page!) You would generate a random number during the process of displaying the form, then store that random number into the user's session under that form's ID. The number would have to be put into a hidden form field in the HTML as well. Then when they submit, you compare the value they send with the value you have stored in their session. The frameworks on Java like Struts can automate this. Perhaps that MVC.PHP which claims to be a port of Struts can also automate it. TX -- 'Every sufficiently advanced technology is indistinguishable from magic' - Arthur C Clarke 'Every sufficiently advanced magic is indistinguishable from technology' - Tom Graves Email: Trejkaz Xaoza [EMAIL PROTECTED] Web site: http://xaoza.net/trejkaz/ Jabber ID: [EMAIL PROTECTED] GPG Fingerprint: 9EEB 97D7 8F7B 7977 F39F A62C B8C7 BC8B 037E EA73 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] include() with a query string?
Is there some way to fake inclusion with a query string attached? I am trying to add a feature to PHP-Mesh (don't know if anyone's heard of it or using it in these parts), basically some user discovered that they can't have portals with query strings attached to the URL. Currently, portals are built something like this: ?php $page-apply_decorator(../portlets/test.php, portlet); ? The contents of the apply_decorator function look like this: ob_start(); // Using require to make errors happen on failure to include a page. require($decorator_selector-get_path($page_location)); $page_contents = ob_get_clean(); // The rest of this stuff's job is to decorate the page which came back. $page = new Page($page_contents); $decorator = $decorator_selector-get_decorator($decorator_name); $decorator-decorate($page); Now, what I want to do is this: ?php $page-apply_decorator(../portlets/test.php?var=1, portlet); ? But when I do that, it can't require the page, because (obviously) the page test.php?var=1 doesn't exist. I was thinking I could use virtual() for this, but it doesn't seem to work properly either... not even if I pass /portlets/test.php?var=1, which I think is a bit odd. Is there some workaround I can use to include a file and have it process the query string? At the moment I'm thinking of saving $HTTP_GET_VARS, then inserting all the variables manually and restoring the hash after the include, but this seems to be a little more complicated than it should need to be. TX -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() with a query string?
Justin Patrin wrote: On Sat, 03 Jul 2004 03:02:07 +1000, Trejkaz Xaoza [EMAIL PROTECTED] wrote: Is there some way to fake inclusion with a query string attached? Yep. Set the $_GET, $_POST, or $_REQUEST vars you need before including. You could also store a backup copy before doing this and put it back after the include if you need it. Okay. This is the way I'm going then. I just noticed also that although $HTTP_GET_VARS is supposed to be an alias for $_GET, I still have to set both variables to account for users' behaviour. (Either that, or I forget about $HTTP_GET_VARS and tell users if it's deprecated in PHP, it's unsupported by my code.) And also, what should I do with $_REQUEST? Do users have to call a function to get that to populate? If that's the case I can silently ignore it since it isn't used anywhere in my code. TX -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() with a query string?
Justin Patrin wrote: It just depends on the vars that the code expects. If it expects them to come via get, it may be $_GET, post, it may be $_POST. Or either of those could be in $_REQUEST (which is populated according to a config var) in a certain order from $_GET, $_POST, and $_COOKIE. In addition, $_GET can be in $HTTP_GET_VARS and $_POST can be in $HTTP_POST_VARS. Both those can be globals if you have register_globals on. So.there's a lot to set if you really want to emulate everything. Well, the code is not my code. It's any code which might be written by someone using PHP-Mesh in the future. So I guess I have to set a hell of a lot of these to make pretend. That being said I only really need to deal with the GET, I guess. Cookies I can treat as being correctly sent already, POST I will just clear out before doing the call (i.e., you can't post to a portlet), and GET I'll populate using parse_str on the query string provided. $_REQUEST is a trouble-maker, and I might just have to forget about it, and tell people to populate it themselves since the function to do so is so easy to use. But the rest is working already so I guess I'm just down to testing it now. Thanks! TX -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php