Jump to content

Daniel0

Staff Alumni
  • Posts

    11,885
  • Joined

  • Last visited

Everything posted by Daniel0

  1. Haha, I liked your example 448191
  2. The syntax highlighting should give you a clue to what is wrong. You forgot to close the string at the first echo.
  3. Just send them to whatever $_SERVER['HTTP_REFERER'] holds.
  4. This will do what mysql_real_escape_string() does: <?php function fake_mysql_real_escape_string($string) { return addcslashes($string, "\x00\n\r\\'\"\x1a"); } ?>
  5. Check if there is a valid session. If yes: Display page - If no: Display login page or redirect to it.
  6. What do you mean with PHP Engine? Could you elaborate please? Do you mean PHP itself?
  7. I don't quite understand what your problem is...
  8. You'd probably have to use some ActiveX script, but that would only work in IE. The PHP code gets executed on the server, therefore the data handling happens on the server. You could also let the user upload the file, then convert it, then let them download it again.
  9. FYI, Java != Javascript
  10. Relative, but I don't really think it matters. Relative paths are just shorter.
  11. The live chat is based on a channel on freenode's IRC server.
  12. Looks pretty good. I'd give the body text a little more line-spacing. It would also be good if you could give the form fields on the contact page another style than the default.
  13. Better (IMO), less "messy": index.php: <?php // Load registry require_once 'registry.php'; $Registry =& Registry::get_instance(); // Require files require_once 'navi.php'; require_once 'session.php'; require_once 'mysql.php'; //... // Make objects $Session = new Session(); $MySQL = new MySQL(); //... // Register objects $Registry->set('session', $Session); $Registry->set('mysql', $MySQL); //... // Run... $Navi = new Navi(); ?> registry.php: <?php class Registry { var $_objects = array(); function &get_instance() { static $me; if(is_object($me)) { return $me; } $me = new Registry(); return $me; } function set($name, &$object) { $this->_objects[$name] = $object; } function &get($name) { return $this->_objects[$name]; } } ?> navi.php: <?php class Navi { var $Session; var $MySQL; function Navi() { $Registry =& Registry::get_instance(); $this->Session =& $Registry->get('session'); $this->MySQL =& $Registry->get('mysql'); } } ?> mysql.php, session.php, ...: Whatever you need in them. Using the registry pattern is really great IMO. You don't need to pass objects around via arguments and you don't need to make objects global using the global keyword.
  14. You'd either have to declare $ifc0nfig as global (not recommended) or use things like a singleton or a registry in order to access the object within other functions/methods.
  15. That's not the way to it then... Read utexas_pjm's post about class relationships again. This will do it: <?php class MySQL { public function some_method() { } } class ifc0nfig { public $MySQL; public function __construct() { $this->MySQL = new MySQL; } } $ifc0nfig = new ifc0nfig(); $ifc0nfig->MySQL->some_method(); ?>
  16. I don't know what you consider easier to read, but here is what you could do: <?php function display_array($array, $level=0) { foreach($array as $key => $value) { $output .= str_repeat("\t",$level); if(!is_array($value)) { $output .= "{$key} = {$value}\n"; } else { $output .= "{$key} = Array:\n"; $output .= display_array($value,$level+1); } } return $output; } $array = array( 'hello' => 'world', 'test' => array( 'sub-thing' => 'hi', 'new_array' => array( 'test1', 'test2', 'test3', array(1,2,3,4), ), ), 'bla' => 'php', ); echo display_array($array); ?> Output is: hello = world test = Array: sub-thing = hi new_array = Array: 0 = test1 1 = test2 2 = test3 3 = Array: 0 = 1 1 = 2 2 = 3 3 = 4 bla = php
  17. Instead of sending them back, render the form again. You are then able to choose which choose which one that is selected. Example (change to fit your code): <?php // ... // $_GET['animal'] holds the selected value $select = array( 'tiger' => 'Tiger', 'elephant' => 'Elephant', 'dog' => 'Dog', //... ); echo "<label for='animal_select'>Please select your favorite animal</label>:\n<select name='animal' id='animal_select'>"; foreach($select as $value => $text) { $selected = $_GET['animal']==$value ? " selected='selected'" : null; echo "\t<option value='{$value}'{$selected}>{$text}</option>\n"; } echo "</select>"; // ... ?>
  18. Would this do it? <?php $img_path = "/path/to/image.jpg"; $img = getimagesize($img_path); list($height,$width) = $img; if($height > 1024 || $width > 768) { echo "Your uploaded image is too large. The maximum allowed size is 1024x768 px. Your image was {$height}x{$width}px."; unlink($img_path); } else if($img['mime']!='image/jpeg') { echo "The image must be a JPEG file."; unlink($img_path); } else { echo "Your image was within the allowed size and has been uploaded."; } ?>
  19. Chances are that you do not have privileges to delete on the two servers which it does not work on (although I don't see any reason why they would restrict that). Does the code above display any errors on the servers it doesn't work on? Is it the query that doesn't work? Have you tried running the query directly on the database (e.g. with a tool like phpMyAdmin)? Or is the code itself that doesn't work?
  20. Isn't PHP4 technically an older version? They don't leave e.g. Firefox 1.5 in the repository either. People could always just download the sources and compile it themselves.
  21. Change to fit your application: <?php $result = mysql_query("SELECT *,((system_nextbillingdate-".time().")/86400) AS days_late FROM cy_members"); ?> If days_late is negative or zero, then they aren't late.
  22. Well. The ability to play the file.
  23. You could choose to hide CSS from Opera because it should not apply the "hack" stylesheets intended for e.g. Internet Explorer. I'm still waiting for the day where IE will be on the same level, in terms of standard compliance, as the other browsers on the market so these hacks are unnecessary.
  24. Check box (and other stuff): http://w3schools.com/tags/tag_input.asp Note: It is a good idea to use labels (especially with radio buttons or check boxes): http://w3schools.com/tags/tag_label.asp Select: http://w3schools.com/tags/tag_select.asp
×
×
  • 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.