Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: PHP help

  1. #1
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default PHP help

    I've got some PHP which essentially writes out some of the details about my objects in an external app into a plist which is basically XML. The only problem is that it isnt writing! It could be a problem with the app but its more than likely PHP because I'm a PHP noob, can anyone see any errors?

    Code:
    <?php
      
      $Object1 = $_POST['Object1']; 
        $Object1x = $_POST['Object1x']; 
        $Object1y = $_POST['Object1y']; 
    
        $Object2 = $_POST['Object2']; 
        $Object2x = $_POST['Object2x']; 
        $Object2y = $_POST['Object2y']; 
    
        $Object3 = $_POST['Object3']; 
        $Object3x = $_POST['Object3x']; 
        $Object3y = $_POST['Object3y']; 
    
        $Object4 = $_POST['Object4']; 
        $Object4x = $_POST['Object4x']; 
        $Object4y = $_POST['Object4y']; 
    
        $Object5 = $_POST['Object5']; 
        $Object5x = $_POST['Object5x']; 
        $Object5y = $_POST['Object5y']; 
    
    $file = 'Values.plist';
    $f_op = fopen($file);
    
    $string = '<?xml version="1.0" encoding="UTF-8"?>';
    fwrite($f_op, $string);
    
    $string = '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">';
    fwrite($f_op, $string);
    
    $string = '<plist version="1.0">';
    fwrite($f_op, $string);
    
    $string = '<dict>';
    fwrite($f_op, $string);
    
    $string = '<key>Item1</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object1 . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item1x</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object1x . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item1y</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object1y . '</string>';
    fwrite($f_op, $string);
    
    $string = '<key>Item2</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object2 . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item2x</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object2x . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item2y</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object2y . '</string>';
    fwrite($f_op, $string);
    
    $string = '<key>Item3</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object3 . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item3x</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object3x . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item3y</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object3y . '</string>';
    fwrite($f_op, $string);
    
    $string = '<key>Item4</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object4 . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item4x</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object4x . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item4y</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object4y . '</string>';
    fwrite($f_op, $string);
    
    $string = '<key>Item5</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object5 . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item5x</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object5x . '</string>';
    fwrite($f_op, $string);
    $string = '<key>Item5y</key>';
    fwrite($f_op, $string);
    $string = '<string>' . $Object5y . '</string>';
    fwrite($f_op, $string);
    
    fclose($f_op); 
    ?>

  2. #2

    Default

    I'm not sure if you can $string = '<?xml version="1.0" encoding="UTF-8"?>'; as wouldn't it close the php connection in the whole file? Not sure...

    Edit: THIS IS USELESS:


    Actually, I just noticed, your fopen is wrong. You forgot to specify a mode http://uk2.php.net/manual/en/function.fopen.php such as
    PHP Code:
    $f_op fopen$file'w' ); 
    where as you just use:
    PHP Code:
    $f_op fopen($file); 
    Last edited by Jam-ez; 05-07-2009 at 02:40 PM.

  3. #3
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Honestly why don't you just do

    PHP Code:
    <?php
      
      $Object1 
    $_POST['Object1']; 
        
    $Object1x $_POST['Object1x']; 
        
    $Object1y $_POST['Object1y']; 

        
    $Object2 $_POST['Object2']; 
        
    $Object2x $_POST['Object2x']; 
        
    $Object2y $_POST['Object2y']; 

        
    $Object3 $_POST['Object3']; 
        
    $Object3x $_POST['Object3x']; 
        
    $Object3y $_POST['Object3y']; 

        
    $Object4 $_POST['Object4']; 
        
    $Object4x $_POST['Object4x']; 
        
    $Object4y $_POST['Object4y']; 

        
    $Object5 $_POST['Object5']; 
        
    $Object5x $_POST['Object5x']; 
        
    $Object5y $_POST['Object5y']; 

    $file 'Values.plist';
    $f_op fopen($file);

    $string '<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Item1</key>
    <string>' 
    $Object1 '</string>
    <key>Item1x</key>
    <string>' 
    $Object1x '</string>
    <key>Item1y</key>
    <string>' 
    $Object1y '</string>
    <key>Item2</key>
    <string>' 
    $Object2 '</string>
    <key>Item2x</key>
    <string>' 
    $Object2x '</string>
    <key>Item2y</key>
    <string>' 
    $Object2y '</string>
    <key>Item3</key>
    <string>' 
    $Object3 '</string>
    <key>Item3x</key>
    <string>' 
    $Object3x '</string>
    <key>Item3y</key>
    <string>' 
    $Object3y '</string>
    <key>Item4</key>
    <string>' 
    $Object4 '</string>
    <key>Item4x</key>
    <string>' 
    $Object4x '</string>
    <key>Item4y</key>
    <string>' 
    $Object4y '</string>
    <key>Item5</key>
    <string>' 
    $Object5 '</string>
    <key>Item5x</key>
    <string>' 
    $Object5x '</string>
    <key>Item5y</key>
    <string>' 
    $Object5y '</string>';

    fwrite($f_op$string);
    fclose($f_op); 
    ?>

  4. #4
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Jam-ez View Post
    I'm not sure if you can $string = '<?xml version="1.0" encoding="UTF-8"?>'; as wouldn't it close the php connection in the whole file? Not sure...
    Ok, cheers, +Rep. Can anyone shed some more light onto this and tell me how I might go about fixing it.

    EDIT: CHEERS BLOB!

  5. #5

    Default

    Quote Originally Posted by FlyDuo View Post
    Ok, cheers, +Rep. Can anyone shed some more light onto this and tell me how I might go about fixing it.

    EDIT: CHEERS BLOB!
    Did what Blob gave work? If not, check my new new edit.

  6. #6
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Jam-ez View Post
    Did what Blob gave work? If not, check my new new edit.
    It didn't but now it does thanks to you! I love you both lol.

  7. #7

    Default

    Quote Originally Posted by FlyDuo View Post
    It didn't but now it does thanks to you! I love you both lol.
    No problem, good luck with whatever you're doing.

  8. #8
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Cheers! Actually, while I'm at it and rather than creating a new thread in the future I have one more question. How can I add or remove users?

    E.G. In the application below up to 3 users can join. Currently User1 and User3 are occupied but not User2.
    Code:
    <?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
    <plist version="1.0"> 
    <dict> 
    
    <key>User1</key> 
    <string>George</string>
    <key>User2</key>
    <string></string> 
    <key>User3</key>
    <string>Ryan</string> 
    
    </dict>
    </plist>
    How could I do it so when someone new joins then their name is sent via POST to fill the User2 String and then when they leave a message is sent via POST so they are removed again.

  9. #9

    Default

    Well I'm not sure what they're leaving but when they're logging in do something like:

    PHP Code:

    $username 
    $_POST['username'];

    // then if we use that to say..

    echo '<key>User1</key> 
    <string>George</string>
    <key>User2</key>
    <string>' 
    $username '</string> 
    <key>User3</key>
    <string>Ryan</string>'

    You'd have to clarify more what you mean... if you wanted me to help more - or just have a go and post what you get.
    Last edited by Jam-ez; 05-07-2009 at 03:14 PM.

  10. #10
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Havent tested it, but try it.

    PHP Code:
    <?php
    $objNum 
    5;

    $file 'Values.plist';

    $string '<?xml version="1.0" encoding="UTF-8"?>';
    $string .= '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">';
    $string .= '<plist version="1.0">';

    $string .= '<dict>';

    for( 
    $i 1$i $objNum$i++ )
    {
        
    $obj $_POST'Object' $i ];
        
    $objX $_POST'Object' $i 'x' ];
        
    $objY $_POST'Object' $i 'y' ];
        
        
    $string '<key>Item' $i '</key>';
        
    $string .= '<string>' $obj '</string>';
        
        
    $string .= '<key>Item' $i 'x</key>';
        
    $string .= '<string>' $objX '</string>';
        
        
    $string .= '<key>Item' $i 'y</key>';
        
    $string .= '<string>' $objY '</string>';
    }

    $string .= '</dict>';

    $handle fopen$file );
    fwrite$handle$string );
    fclose$handle );
    ?>
    Hi, names James. I am a web developer.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •