Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

php help of a non-convertible class.

I have a php access code that communicates with the db of course , and sends the user id logged returning based user id its nickname , the problem is that I should do a file within its folder nick ( the folder is done automatically during recording and I did it with mkdir and never gave me problems ) . But now with fopen I try to write in the folder based on always their user name and a randomly generated number . But now nell'fopen unlike mkdir folder with the same variable ( indicating the name of the folder that corresponds to the nickname ) , he says that the object of the class can not be converted to the string ...

Why? how do I fix ?
This is really incomprehensible, could you please avoid useless sentence and try to be clear?

Also, provide us your code and the exact error message.
(Jun 9, 2016 12:51 PM)Yani Wrote:  Why? How do I fix?

WHY?

HOW?

Post your code man. It seems you're using a class wrong.

PHP Code

<?php 
$class
->string;
$class->function();
$class; 

Don't use the class variable (which is the class object), as a string.

Edit; I GOT THE GREEN CLOVER FOR THIS POST LOL

You got a clover award just for repeating the exact same thing as me?????
(Jun 9, 2016 12:54 PM)Sakuto Wrote:  You got a clover award just for repeating the exact same thing as me?????

Maybe if I do it I will get one too :)
Never mind the form of registration and of autentication with the various functions for communicate with the db. I have this class call iscritions that the login returns the nick;

class + function this is:

file.functions.php:
Code
@include_once 'connect-database.php';

class Iscrizioni{
  public function mostra_username($id_utente) {
  $query = @mysql_query("SELECT nome_utente FROM iscritti WHERE id_utente = $id_utente") or   die(mysql_error());
  $risultato = mysql_fetch_object($query);
  echo $risultato->nome_utente;
  $e = htmlentities($risultato);
  return $e;
}
}
Now I want via the terminal is saved to a file ( by calling the function from another page ) , the file is saved in the folder that is named with the same nickname returned by the function :
Code
<?php
@include_once 'funzioni.php';
$obj = new Iscrizioni();
$id_utente = $_SESSION['id_utente'];

$contenuto = "contenuto da stampare";

$obj->mostra_username($id_utente); //richiamo e invio dell'id utente della sessione per la restituzione del nickname

$rand_number = rand (0,99999999999999); //genera numero casuale per il nome del file

$fetch = "$obj/$rand_number";  //errore di conversione che voglio risolvere

$fw = fopen ("./$fetch.txt","w");
fwrite ($fw,"$contenuto");
fclose ($fw);

?>
Obviously the one here is only a sketch of all the code as I said , and returns me the error : " The object of the class can not be converted to a string " :

how to solve ?
You probably mean to do:

PHP Code

<?php 
$risultato 
= mysql_fetch_object($query);
$e = htmlentities($risultato->nome_utente); 
(Jun 10, 2016 04:10 AM)Sakuto Wrote:  You probably mean to do:

PHP Code

<?php 
$risultato 
= mysql_fetch_object($query);
$e = htmlentities($risultato->nome_utente); 
thus it remains vulnerable to XSS correct? another way ?
XSS in a text file...? No, this is not possible :D You will never display the text you get so I don't even see the point of the htmlentities
(Jun 10, 2016 05:00 AM)Sakuto Wrote:  XSS in a text file...? No, this is not possible :D You will never display the text you get so I don't even see the point of the htmlentities
ok ok thnk perfect..


Boys with tips that you gave me , now does not give me more errors , but the file is not actually created ....


(Jun 10, 2016 05:00 AM)Sakuto Wrote:  XSS in a text file...? No, this is not possible :D You will never display the text you get so I don't even see the point of the htmlentities

Boys with tips that you gave me , now does not give me more errors , but the file is not actually created ....
Code
$fetch = "$obj/$rand_number";  //errore di conversione che voglio risolvere

$obj can't be appended to a string since it's holding your class object. What are you hoping $fetch will look like after that code? It should be still giving you errors.

If you can post your updated code with a clear explanation of what you're trying to do and what's wrong, it'd make it easier.
But as I said , the directory is created at the time of account registration , and already exists . what's the problem?
(Jun 10, 2016 12:34 PM)clemme Wrote:  But as I said , the directory is created at the time of account registration , and already exists . what's the problem?

In that case it's likely permissions. Chmod your folders to allow for writing from user/group.
Do you have any error or it's just not working? And are you sure you did not fully removed the return part?
the creation of the folder right after I give the read and write permissions with chmod 777
but nothing
(Jun 11, 2016 12:40 AM)clemme Wrote:  the creation of the folder right after I give the read and write permissions with chmod 777
but nothing

So the folder is created but the file isn't? Please post all your code and refer back to my previous post.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by Jeffr0May 31, 2022 11:51 AM 9 413 May 31, 2022 11:51 AM
Last Post: Yoyo95
[PHP] by DurendalMay 1, 2015 12:22 AM 2 260 May 1, 2015 12:22 AM
Last Post: Durendal
[PHP] by Ego IncJan 29, 2015 02:01 PM 17 663 Jan 29, 2015 02:01 PM
Last Post: Support Operator