Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JonnoTheDev

  1. The value is reset. You cannot give a file type input a value. If you could do then I could upload any file from your computer just by you visiting my website and submitting a form without you even browsing for a file. I could simply hide the field and use a fixed value in the input element. If a form is submitted the file input will be reset once the form processing script has completed.
  2. Always use mysql_real_escape_string on any data that you insert / update / select with if it comes from GET / POST / COOKIE / SESSION data! $sql = "Update tbl123 SET title='".mysql_real_escape_string($title)."', category='".mysql_real_escape_string($category)."', ingredient1='".mysql_real_escape_string($ingredient1)."', ingredient2='".mysql_real_escape_string($ingredient2)."' WHERE id ='".mysql_real_escape_string($id)."'";
  3. Yes. This is your problem. Shared hosts are often on spam mail databases as other users of the web server are probably running scripts to send out lots of email. Contact your web host and get them to sort this out. Once this server has been removed from the databases you will find that your email gets through to hotmail, gmail, etc. However, there is still the chance that the server will be blacklisted again in the future. You will have to raise this issue with the web host.
  4. <?php $path_to_dir = '/path/to/images/dir/2012/'; if ($handle = opendir($path_to_dir)) { while (FALSE !== ($entry = readdir($handle))) { if ($entry != '.' && $entry != '..' && !is_dir($entry) && preg_match('/jpg|gif|png/i', $entry)) { echo "<img src=\"" . $path_to_dir . $entry . "\" />\n"; } } closedir($handle); } ?>
  5. I would write a php script to do this by simply looping over each database. I'm guessing that all the databases are on the same server. If not you will need to grant access from wherever the script runs.
  6. The server is probably on a spam database. This is a problem using a shared server. Find out what the IP address of your server is. You can simply ping your domain to get this. Once you have the IP address go to the following URL http://www.webwiz.co.uk/domain-tools/spam-database-lookup.htm Enter the IP and click search. If the IP comes up as blacklisted on any of the databases you will have to either contact your webhost to get it removed or go to the database in question and try to get it removed yourself.
  7. Yes, but in the general sense HTML (no modification of php.ini, etc.) is static and cannot contain server side code.
  8. Yeah they do. Napoleon Dynamite!
  9. They are probably just obfuscating it by using javascript to create a script element within the DOM. Something like this http://stackoverflow.com/questions/610995/jquery-cant-append-script-element To be honest I wouldn't even bother. Why try to hide your js includes. Just minify them.
  10. <?php // ob_start(); include_once "connect_to_mysql.php"; $my_url = 'http://www.yourwebsiteurl.com'; $goto_index = FALSE; if(!isset($_SESSION['loginredirect'])) { if(!strstr($_SERVER['HTTP_REFERER'], $my_url)) { $goto_index = TRUE; } else { // do not redirect to any of these pages (add as you need) $noredirect = array('login.php', 'logout.php'); foreach($noredirect as $file) { if(strstr($_SERVER['HTTP_REFERER'], $file)) { $goto_index = TRUE; } } } $_SESSION['loginredirect'] = ($goto_index) ? $my_url : $_SERVER['HTTP_REFERER']; } // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" // session_register has been depreciated. Must figure use another function? session_register("myusername"); session_register("mypassword"); // $_SESSION["myusername"]; // $_SESSION["mypassword"]; //header("location:bo.php"); header('Location:' . $_SESSION['loginredirect']); exit() } else { echo "Wrong Username and Password"; } // ob_end_flush(); ?> Why are you storing the users password in a session. You should never do this. You should store something that can tie them up to the database such as their ID.
  11. You could use this simple bit of code on your login file. This will store the referring url. <?php $my_url = 'http://www.yourwebsiteurl.com'; $goto_index = FALSE; if(!isset($_SESSION['loginredirect'])) { if(!strstr($_SERVER['HTTP_REFERER'], $my_url)) { $goto_index = TRUE; } else { // do not redirect to any of these pages (add as you need) $noredirect = array('login.php', 'logout.php'); foreach($noredirect as $file) { if(strstr($_SERVER['HTTP_REFERER'], $file)) { $goto_index = TRUE; } } } $_SESSION['loginredirect'] = ($goto_index) ? $my_url : $_SERVER['HTTP_REFERER']; } ?> After login is successful you can redirect the user using <?php header('Location:' . $_SESSION['loginredirect']); exit(); ?>
  12. You cannot use php code if the file does not have a php extension. To use dynamic data in a HTML document would require Javascript to make an ajax call to a server side script. The simplest way to make data persist through multiple pages is to store it in a session. I can then be accessed on any page until it is destroyed.
  13. I think the main problem is a lack of good teachers in the IT sector. It's a huge problem in the UK (unsure about the US) that the government are only just starting to recognise and act on, as a more and more programming, games development, and software engineering projects are being outsourced overseas due to a shortage of good programmers. If it were myself doing this course I would raise concerns with the head teacher (or whatever you guys call it in the US) about the standard of the lessons and the teaching methods. On another note, this brilliant device is what is going into schools in the UK for children of a really young age to learn programming skills. I think it is excellent. http://www.raspberrypi.org/faqs
  14. I think you must have a spelling error in your WHERE claus. You have spelled, 'category' with an, 'a' instead of an, 'e'. Check the database field name is spelled correctly as it MUST match the spelling in query. $data = mysql_query("SELECT * FROM youtube_playlists WHERE category='individual'") or die(mysql_error());
  15. Thats simple <?php function get_tld($domain) { $parts = parse_url($domain); if(!isset($parts['path'])) { return FALSE; } $domain = $parts['path']; return trim(substr($domain, strpos($domain, '.', 0) + 1, strlen($domain))); } echo get_tld('google.com') . '<br />'; echo get_tld('google.co.uk') . '<br />'; echo get_tld('foobar.uk.com') . '<br />'; // this one is bad echo get_tld('http://www.google.es'); ?>
  16. Essentially, yes. Although I don't think qBasic or Cobol will help you much. Just the High Level Object Oriented languages.
  17. If you are used to using a specific php framework i.e cake, codeigniter, etc and you start using Rails you will come across things like presenters for views and loading views into layouts, autoloading views & models, etc (loads of stuff). Going back to your php you may start implementing some of these features to make life easier hence improving your code and following the Rails method of convention over configuration so you can keep your projects consistent. I'm not saying that using Rails makes your general everyday php coding better. I'm stating that once you see how Rails tackles a certain problem you may start to think, 'well can I do that with my php code to make it more efficient'.
  18. ROR is such a great thing to have on your CV. I have not touched it for a few years but it is an excellent framework for web development. Many big sites are built using it. I think Twitter is one of them. Using ROR may actually help you improve your php coding. As gizmola has stated, many of the top end php frameworks are using ROR methods. I am currently flicking through the following book https://efendibooks.com/books/codeigniter-handbook/vol-1 which adapts the codeigniter framework to work more like ROR.
  19. It means use a hardcoded value i.e define('SITE_EMAIL_ADDRESS', 'joe@bloggs.com'); As the site email address will never change (it is constant) it is hardcoded into a CONSTANT. Data which comes from the superglobal arrays $_POST, $_GET, etc is NOT constant. It can be ammended by a user. The answer is to hardcode a value. There is no need to post it through a form or send it through the url as it will always be available if you are including you constants definintion file throughout your site.
  20. Your use of objects is wrong. Member variables can contain default values simply by setting them when the are declared. A class should not hold an instance of itself unless you are using the SIngleton pattern. This is where you would not want the object to accidentally be redeclared and its values reset i.e a database object. A second object can hold instances of the first object and use its methods. See below <?php // a simple class class foo { public $color = '#5432FA'; public $size = '5.3'; public function __construct($color = FALSE, $size = FALSE) { if($color) { $this->color = $color; } if($size) { $this->size = $size; } } public function get_color() { return $this->color; } public function get_size() { return $this->size; } } // another simple class that contains foo objects class bar { protected $foos = array(); public function add_foo(foo $foo) { $this->foos[] = $foo; } public function display_foo_data() { foreach($this->foos as $foo) { print "<p>Color: ".$foo->get_color().", Size: ".$foo->get_size()."</p>"; } } } // usage $a = new foo(); $b = new foo('#FFFFFF', 10); $c = new foo(); $bar = new bar(); $bar->add_foo($a); $bar->add_foo($B); $bar->add_foo($c); $bar->display_foo_data(); ?>
  21. I would hate managers being there. In my old place we would go out for lunch on a Friday. This was prime time to bitch and slag off all the overpaid managers who did f*** all!
  22. This made me laugh. It reminds me of mission control at NASA or some NSA type Kiefer Sutherland Jack Bower 24 episode.
  23. Some nice offices. Mine's a bit of a tip at the moment.
  24. High profile websites mostly always serve content relevant to the device they is being accessed through. If I access the website on an iPad I will get a version that will display smaller images, less textual content and no flash. If I access the website on my smartphone there will be less javascript, much smaller images, smaller stylesheets, no flash, etc. If I access the device on a PC then I get the full blown version. This is how websites are designed to cater for all devices, even including Smart TVs. They are not designed to change based from connection speed (mobile versions are the exception). Designing mobile friendly sites is not just about the screen resolution. They are designed with the thought that they are being accessed through a mobile network and not a WIFI connection and are scaled down so that the content is served quickly. If a mobile user has a WIFI connection then mobile versions usually have a link that can take them to the full blown website. I would certainly not go down the route of building a website that serves different content based from an ajax call to determine the users connection speed. There are just too many holes with a solution like this. There are methods I have read about for mobile devices running Android to get the connection speed but certainly not used for a full blown desktop website. There are tools to use to detect what devices are accessing your website and serve the appropriate version to them. Look at WURFL http://wurfl.sourceforge.net/ Psycho was correct in his post
  25. It isn't going to make any difference which submit button is clicked as they are all contained in the same form. Once a button is clicked the $_POST array will contain the value of the last button (if the buttons all have the same name attribute) or it will contain the values of all the buttons. You will never know which has been pressed. You can either update all of the records shown on the page i.e if there are 6 text fields then update all 6 records when a submit button is clicked, or you will have to contain each row within its own form and use a hidden field within each that contains the id of the record.
×
×
  • 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.