Jump to content

ChadNomad

Members
  • Posts

    46
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ChadNomad's Achievements

Member

Member (2/5)

0

Reputation

  1. I though this was the case. As its my own code I probably don't realise the inconsistencies I'm making for everyone. Thanks. I think its reaffirmed my suspicion that its all too unnecessary. Thanks guys
  2. Hi all, I am nitpicking here but I have wondered what the negatives are of assigning local variables to existing class variables are. To make more sense here is an example: <?php class myClass { private $_something; public $config = array( 'setting' => 123, ); public function __construct(array $config) { $this->config = $config; } public function go() { /* * Is this considered bad? I know an extra variable is being made * but I find it tedious constantly using $this, static, self etc */ $something = $this->_something; if($something) ... /* * Another thing I've found myself doing is typecasting arrays * to objects to save time typing. Is this bad? */ $config = (object) $config; if($config->setting === 123) ... } } I work alone mostly and have just started to become curious about all the bad habits I have. Thanks
  3. Hey all, Another OOP question from me Is using constants in a class a bad idea? For example I have a config file and have this in a class: header("Location: ".LOGIN_LOCATION); Also is it OK to define $_SERVER variables in a construct? For example I have: class whatever { private $_remote_addr; private $_user_agent; function __construct() { $this->_remote_addr = $_SERVER['REMOTE_ADDR']; $this->_user_agent = $_SERVER['HTTP_USER_AGENT']; } .. or is it OK just to use $_SERVER for example in a mysql query? Thanks for all the help so far. Getting there!
  4. I think* you would need a unique name for each checkbox. If a checkbox is ticked/tiked it posts as "on". So... if($_POST['checkbox_name'] == "on") { // It's checked }
  5. Hi. I've been learning OOP and watched a about a "secure" OOP PHP login script. It was pretty good, and helped me to understand some OOP approaches, but I couldn't help thinking some of it was wrong. I'm not sure so feedback appreciated! The class starts of something like this: <?php class Login { private $_id; private $_username; private $_password; private $_passmd5; private $_errors; private $_access; private $_login; private $_token; public function __construct() { $this->_errors = array(); $this->_login = isset($_POST['login'])? 1 : 0; $this->_access = 0; $this->_token = $_POST['token']; $this->_id = 0; $this->_username = ($this->_login)? $this->filter($_POST['username']) : $_SESSION['username']; $this->_password = ($this->_login)? $this->filter($_POST['password']) : ''; $this->_passmd5 = ($this->_login)? md5($this->_password) : $_SESSION['password']; } Isn't "hard" setting variables, like the POST vars in the contruct bad? Shouldn't they be passed through elsewhere? I've learnt that OOP needs to be reusable and manageable as it's primarily the point of using OOP in the first place. I might be wrong but I noticed straight away that the above class doesn't seem reusable (in the true sense). Hopefully i'm getting the hang of it... Thanks
  6. Hi. I want my code to be more efficient and logical and was wondering if anyone could point me in a good direction? For example i concatenate a lot of stuffs as well as escaping a lot. Example; $content = "<p>something</p>".$content; mysql_query("UPDATE the_table SET content='".$content."' WHERE id='".$r['id']."'") or die (mysql_error()); I cant think of any others right now but i'm sure i have lots of bad practices. Thanks
  7. Hi all, Is it possible to use an already open socket? Sorry I'm finding it difficult to describe this. I have created a persistent connection to a service with this: $connection = pfsockopen($servier, $port, $errno, $errstr) or exit($errno . " " . $errstr); Using a while look like while (!feof($connection)) I can use fputs to send through the socket. My question... Can I find and use an already open socket from another file completely unrelated so I can send custom commands "on the fly" so to speak? Everything I've tried has landed me with supplied argument is not a valid stream resource so far... Any help appreciated. Thanks
  8. Thanks for the help. That did it (I'm not any good with regular expressions). I ended up with this: $content = preg_replace('/\[img\](.*?)\[\/img\]/is', '', $r['body']); As it's the only tag I don't want parsed. Thanks
  9. Sorry I have googled. I don't want to parse BB code, I want to remove everything within certain tags. So: [img=image] is completely removed. The tag, the content imbetween too. I appreciate the reply though.
  10. I am getting news from a column that's in BB Code. I want snippets as "news" but I'm having some problems. For example some code that comes out is [img=http://linktoimage.com] which I want to remove. Basically I would like to remove the tags and the text inside! Help appreciated, thanks.
  11. I'm writing a class (or trying) to make forms quicker to produce. Heres an example function: function input($type, $class, $value, $newline) { if (!empty($type)) { $html .= "type=".$type.self::space; } if (!empty($class)) { $html .= "class=".$class.self::space; } if (!empty($value)) { $html .= "value=".$value.self::space; } if (!empty($newline)) { $html .= self::lineBreak; } $this->output = '<input '.$html.' />'.self::newLine; echo $this->output; } What would be a better approach to all the if statements or is that perfectly fine? Thanks
  12. You really do need to show more code... If you want to hide the image use CSS. For example: <img src="<?php echo $row_motos['img2']; ?>" width="250" height="187" border="0" style="visibility:hidden;" />
  13. Can't you just replace the spaces with %20 with str_replace? <?php $url = "www.site.com/uploads/this is a test.doc"; // www.site.com/uploads/this%20is%20a%20test.doc echo str_replace(" ", "%20", $url); ?>
  14. The reason your getting the "X" image with Internet Explorer is because the image doesn't exist (or your linking to it wrong). That's just the way the browser behaves. Are you sure you aren't trying to display an image depending on whether it's set in your array? You could do something like: if (isset($row_motos['img1'])) { // print the HTML for img1 } else { // print the HTML for img2 } ??
  15. What does this output? print_r($row_motos);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.