OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 5 Mar 2005 12:39:07 -0000 Issue 3320

php-general-digest-helplists.php.net
Date: Sat Mar 05 2005 - 06:39:07 CST


php-general Digest 5 Mar 2005 12:39:07 -0000 Issue 3320

Topics (messages 210056 through 210065):

Re: Image Submits to Forms
        210056 by: Marek Kilimajer

setcookie
        210057 by: Randy Johnson
        210058 by: Marek Kilimajer
        210059 by: Randy Johnson
        210060 by: Randy Johnson

Re: Document root, preferred way to find it???
        210061 by: Tom Rogers
        210062 by: Tom Rogers

Re: line feed
        210063 by: Tom Rogers

swaping mysql table values
        210064 by: Dave Carrera
        210065 by: Jochem Maas

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


Marquez Design wrote:
> Greetings,
>
> I am trying to create a form that will do the following:
>
> First, select a page from a select box,
> Second, click on a button on the side that will do a specific function.
>
> Select page, then with the delete button, delete the file,
> Select page, then with the edit button, edit the page.
>
> Does anyone know how I could do this?

HTML of the buttons:

<input type="image" src="delete.gif" name="delete">
<input type="image" src="edit.gif" name="edit">

Then in the form handling script:

if(isset($_POST['delete_x']) && isset($_POST['delete_y']) {
        // delete
}

if(isset($_POST['edit_x']) && isset($_POST['edit_y']) {
        // edit
}

If every browser was standards compliant, you could use:

<input type="image" src="delete.gif" name="action" value="delete">
<input type="image" src="edit.gif" name="action" value="edit">

switch($_POST['action']) {
        case 'delete':
                // delete
                break;
        case 'edit':
                // edit
                break;
}

attached mail follows:


setcookie( "sess_key",$key,0,"/","." . str_replace(
"www","",$_SERVER["SERVER_NAME"] ),0 );

Does that look right?

Thanks!

Randy

attached mail follows:


Randy Johnson wrote:
> setcookie( "sess_key",$key,0,"/","." . str_replace(
> "www","",$_SERVER["SERVER_NAME"] ),0 );
>
>
> Does that look right?

No.

if $_SERVER["SERVER_NAME"] == 'www.domain.com'

"." . str_replace("www","",$_SERVER["SERVER_NAME"] )

will give you "..domain.com"

attached mail follows:


ok I see how that could be an issue.

Here is my big problem that I have not been able to figure out.

I have a client website that I am trying to fix

1. it has sessions in database, and uses set cookie

2. I can login with firefox/netscape/mozilla just fine

3. I cannot login with any version of IE

4. this is also by going to domain.com or www.domain.com, neither work

any ideas?

Randy

Marek Kilimajer wrote:
> Randy Johnson wrote:
>
>> setcookie( "sess_key",$key,0,"/","." . str_replace(
>> "www","",$_SERVER["SERVER_NAME"] ),0 );
>>
>>
>> Does that look right?
>
>
> No.
>
> if $_SERVER["SERVER_NAME"] == 'www.domain.com'
>
> "." . str_replace("www","",$_SERVER["SERVER_NAME"] )
>
> will give you "..domain.com"
>

attached mail follows:


The period was the issue all together, i took the extra out and it
worked. Thanks for your help

Randy

Randy Johnson wrote:
> ok I see how that could be an issue.
>
> Here is my big problem that I have not been able to figure out.
>
> I have a client website that I am trying to fix
>
> 1. it has sessions in database, and uses set cookie
>
> 2. I can login with firefox/netscape/mozilla just fine
>
> 3. I cannot login with any version of IE
>
> 4. this is also by going to domain.com or www.domain.com, neither work
>
>
> any ideas?
>
> Randy
>
>
>
> Marek Kilimajer wrote:
>
>> Randy Johnson wrote:
>>
>>> setcookie( "sess_key",$key,0,"/","." . str_replace(
>>> "www","",$_SERVER["SERVER_NAME"] ),0 );
>>>
>>>
>>> Does that look right?
>>
>>
>>
>> No.
>>
>> if $_SERVER["SERVER_NAME"] == 'www.domain.com'
>>
>> "." . str_replace("www","",$_SERVER["SERVER_NAME"] )
>>
>> will give you "..domain.com"
>>
>

attached mail follows:


Hi,

Saturday, March 5, 2005, 5:47:07 AM, you wrote:
LG> Hello Richard,

LG> Friday, March 4, 2005, 11:41:29 AM, you wrote:
R>> http://php.net/set_include_path

LG> Ok... Maybe I should put all this together in one e-mail so that all
LG> the issues can be looked at...

LG> The problem:

LG> Finding a reliable method to include files, keeping in mind the
LG> following:

LG> 1. The site could be moved to a completely new host which could be of
LG> a different OS, and/or web server software, and could either be the
LG> one and only site on that host (dedicated server), or could be a
LG> virtual host (shared server).

LG> 2. The site could remain on the same host but is required to move to a
LG> new path. i.e. from htdocs/mysite to htdocs/mynewsite

LG> 3. The web host may or may not allow the use of .htaccess (Some Sambar
LG> configurations for example).

LG> 4. The method used would not affect any other virtual hosts. Meaning,
LG> the method used must be independent for each virtual host.

LG> 5. The method used would not utilize a folder where other virtual
LG> hosts could gain access to the included file (php.ini
LG> include_path).

LG> 6. The method (and this is the important one IMHO) would not require
LG> editing "x" number of pages in a site to change some static path
LG> that was set on each page.

LG> 7. The method used would not require a dedicated "include" file in
LG> every single folder of the site that could be included because it's
LG> in the same folder as the page needing it, because those would all
LG> have to be edited to fix the path if condition 1 or 2 was met.

LG> Previously proposed solutions:

LG> 1. PHP.ini include_path
LG> This affects all virtual hosts and would require administrative
LG> overhead to prevent the owners of each virtual host from gaining
LG> access to other virtual host's include files. I suppose you could
LG> set it to something like: include_path="/php/includes" and have a
LG> separate subfolder under that for each virtual host. But since that
LG> folder is outside the web folder, there would have to be some
LG> mechanism (additional FTP account) for each person to gain access
LG> to their own include folder to add/edit/delete files in that
LG> folder. Then if the site is moved and they aren't using an
LG> include_path, you have to fix all your pages.

LG> 2. set_include_path
LG> This means if your site moves, you must edit "x" number of pages in
LG> the site to correct the path.

LG> 3. An include file in every directory to set the include path.
LG> You'd have to edit "x" number of these files to correct the path if
LG> the site moves. This would be much less work than the previous
LG> item, but it could be a lot of work on very big sites where you
LG> don't have shell accounts to do some scripted find/replace with.

LG> 4. Use the full URL to the file in the include statement.
LG> See item 2.

LG> 5. $_SERVER["DOCUMENT_ROOT"] and $_SERVER['PATH_TRANSLATED']
LG> Not always available or incorrect see
LG> mid:1778675148.20050303102623kwikin.com

LG> I may have missed some things, and if I've misunderstood how something
LG> should work, then please let me know. I'm just looking for a more or
LG> less foolproof method which doesn't require fixing code if the site is
LG> moved. The closest I can come to it is the function I wrote but is a
LG> pain because you have to put it in every page where you need an
LG> included file. Granted, you only have to do it once, and then you're
LG> done and a site move wont affect it, but it's still kludgy if you ask
LG> me.

LG> *******************
LG> <?php
LG> function dynRoot()
LG> {
LG> $levels = substr_count($_SERVER['PHP_SELF'],"/");

LG> for ($i=0; $i < $levels - 1; $i++)
LG> {
LG> $relativeDir .= "../";
LG> }

LG> return $relativeDir;
LG> }
?>>
LG> *******************

LG> and then calling it as such:

LG> include(dynRoot() . 'includes/db_connect.php');

LG> I've had to move client sites between Sambar, Apache, IIS and Windows,
LG> Linux. Most times I've had to go in and fix include paths because one
LG> of the above solutions were originally used and wasn't viable on the
LG> new host.

LG> Thanks.
   

LG> --
LG> Leif (TB lists moderator and fellow end user).

LG> Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
LG> Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

This will set the include path just before the document root:

if(isset($_SERVER["SCRIPT_FILENAME"])){
        $root = $_SERVER['SCRIPT_FILENAME'];
        //echo "Root: $root<br>";
        
        $script = $_SERVER['SCRIPT_NAME'];
        $document_root = str_replace($script,'',$root);
        //echo "Document root: $document_root<br>";
        
        $base = basename($document_root);
        //echo "Base: $base<br>";
        
        $include = str_replace($base,'include',$document_root);
        //echo "Include: $include<br>";
        
        $os = strtolower(PHP_OS);
        //echo "OS: $os<br>";

        $lk = ':';
        $org_include = ini_get("include_path");
        if(preg_match('/^win/i',$os)) $lk = ';';
        
        ini_set("include_path",$include.$lk.$org_include);
        //echo "Include: ".ini_get("include_path")."<br>";
}

--
regards,
Tom

attached mail follows:


Hi,

TR> This will set the include path just before the document root:

TR> if(isset($_SERVER["SCRIPT_FILENAME"])){
TR> $root = $_SERVER['SCRIPT_FILENAME'];
TR> //echo "Root: $root<br>";
        
TR> $script = $_SERVER['SCRIPT_NAME'];
TR> $document_root = str_replace($script,'',$root);
TR> //echo "Document root: $document_root<br>";
        
TR> $base = basename($document_root);
TR> //echo "Base: $base<br>";
        
TR> $include = str_replace($base,'include',$document_root);
TR> //echo "Include: $include<br>";
        
TR> $os = strtolower(PHP_OS);
TR> //echo "OS: $os<br>";

TR> $lk = ':';
TR> $org_include = ini_get("include_path");
TR> if(preg_match('/^win/i',$os)) $lk = ';';
        
TR> ini_set("include_path",$include.$lk.$org_include);
TR> //echo "Include: ".ini_get("include_path")."<br>";
TR> }

TR> --
TR> regards,
TR> Tom

Forgot to tell you to put it in the auto_prepend file and it will work
for all files :)

--
regards,
Tom

attached mail follows:


Hi,

Saturday, March 5, 2005, 12:38:20 AM, you wrote:
BS> Hello.

BS> How do i print a line return using the echo command, for when i see the
BS> page source,
BS> i get the code line by line and not all in the same line.

BS> using double quotes ( " ), i can put \n at the end and i get the result
BS> i want,
BS> but, using sinle quotes ( ' ), \n doesnt work.

BS> if i use double quotes, in a simple html comand i need to use \" and i
BS> dont want that.

BS> is any way i could use single quotes, and getting the line feed ??
BS> example:
BS> Double quotes:
BS> echo "<table border=\"1\" width=\"800px\">\n";

BS> single quotes:
BS> echo '<table border="1" width="800px">';

BS> cheers

BS> Bruno Santos

BS> --
BS> Say no to software patents
BS> www.nosoftwarepatents.com/
BS> --
BS> bvsantoshal.min-saude.pt
BS> --
BS> Divisao de Informatica
BS> informaticahal.min-saude.pt
BS> Tel: +351 272 000 155
BS> Fax: +351 272 000 257
BS> --
BS> Hospital Amato Lusitano
BS> geralhal.min-saude.pt
BS> Tel: +351 272 000 272
BS> Fax: +351 272 000 257

you could do:
define('LF',"\n");
echo '<table border="1">'.LF;

--
regards,
Tom

attached mail follows:


Hi List,

I have a table like the diag below:

ID Name Pos
1 jig 1
2 pig 2
3 dig 3
4 fig 4

What i am trying to do is upon click to change pos 1 to pos 2 and pos 2
to pos 1so that i can manage the position i show my list.

Can someone throw me some nuggets of logic wisdom as my searchs are
coming up blank.

Thanks you in advance

Dave C

attached mail follows:


Dave Carrera wrote:
> Hi List,
>
> I have a table like the diag below:
>
> ID Name Pos
> 1 jig 1
> 2 pig 2
> 3 dig 3
> 4 fig 4
>
> What i am trying to do is upon click to change pos 1 to pos 2 and pos 2
> to pos 1so that i can manage the position i show my list.
>
> Can someone throw me some nuggets of logic wisdom as my searchs are
> coming up blank.

here is a description of a simple ordering mechanism, hope it gives you
an idea how to proceed:

1. output a table that reflects the current order.
    each row should have (at least) 2 links: 'move up' & 'move down',
    the links should have GET params for the direction you want to the
    position to change to and the id of the item whose position you want to
    change.

2. if a user clicks on one of those links do the following processing:

    MOVE DOWN:
        1. determine the selected items current 'position'
         2. find the item whose 'position' is the next greatest (value) after
            the selected items 'position'
        3. if an item with greater 'position' is found then do:
                a, update selected items position with position value of item found
                    in step 2
                b, update the 'position' of the item found in step 2 with the 'position'
                   value of the selected item.
    MOVE UP:
        1. determine the selected items current 'position'
         2. find the item whose 'position' is the next lowest (value) after
            the selected items 'position'
        3. if an item with lesser 'position' is found then do:
                a, update selected items position with position value of item found
                    in step 2
                b, update the 'position' of the item found in step 2 with the 'position'
                   value of the selected item.

3. go back to step 1. (output a table!)

>
> Thanks you in advance
>
> Dave C
>