-
Posts
2,965 -
Joined
-
Last visited
Everything posted by mikesta707
-
so someone is going to go through every one of the files they want to include, and apply a sha1 hash to all of them? No offense, but that just seems kind of dumb. and I did provide an alternative.. file_get_contents + eval, but thats just a slower version of include, which I also stated. I don't even understand why OP doesn't want to use include, or one of its sister functions, but whatever
-
[SOLVED] Display certain image depending on time of year
mikesta707 replied to Daveed1973's topic in PHP Coding Help
you can also use F or M to get textual representations of the month, if that floats your boat -
turning an array into a string then poping it into a db
mikesta707 replied to gotornot's topic in PHP Coding Help
look into serialize() -
[SOLVED] Display certain image depending on time of year
mikesta707 replied to Daveed1973's topic in PHP Coding Help
I would use a switch case statement, rather than a bunch of if elseif's $month = date("m"); switch($month){ case "09": //do october stuff break; case "12": //do december stuff break; default: //de default banner break; } -
[SOLVED] Form returning empty but no errors??
mikesta707 replied to cmaclennan's topic in PHP Coding Help
do you know what the @ symbol does? $result = @mysql_query ($query); // Run the query it suppresses errors, so that is probably why you aren't getting an error. plus, you should do this $result = mysql_query ($query) or die(mysql_error()); // Run the query to see what errors mysql might be spitting back at you. It seems like your query is failing -
if a PHP programmer has acess to your pages.. than the last thing you need to worry about is obfuscating your page name. and technically, this isn't obfuscating the code, because the code remains untouched. Also, unless you sha1 the actual file names of the files themselves, this method is kind of dumb if you really want to inlude a page without explictely using the "include" function, you can use get file contents, and eval... but thats just a really dumb way of using include. is there any reason you don't want to use include? PHP code is already hidden so i don't really see the problem
-
$filestructure = scan_directory_recursively('/var/www/'); print_r($filestructure[0]['content']); that should give you an idea of how to proceed
-
I think i'm using the syntax incorrectly
mikesta707 replied to horizontal's topic in PHP Coding Help
ok, we in that case, you can use regular expressions to replace the brackets, and anything between with nothing. I'm not very good with regex, so I dont want to steer you wrong, but try finding a tutorial on regex. -
I think i'm using the syntax incorrectly
mikesta707 replied to horizontal's topic in PHP Coding Help
well as long as every email between the commas is ONE email, than its fine. if you want to take "<blah@sdk.net>blah@sdk.net" and split that into two things, then you will have to change the code up -
assuming your array will always be in order, this is probably the only way, since you can't use strtotime() in the way that would make your task a lot easier. However, if your array has even the slightest chance of having non- monday dates, you may run into problems. i think you need a new host
-
I think i'm using the syntax incorrectly
mikesta707 replied to horizontal's topic in PHP Coding Help
if i wanted to get an array of the different emails (assuming that every single email was seperated by a comma) I would do this $content = file_get_contents('email.txt'); $emails = array(); $emails = explode(',', $content); array_map("trim", $emails);//this just removes trailing or leading whitespace from all the entries -
$_POST['theArray']['name'][$i] did you try that. I think multidimensional post arrays are set up like post - field - field[0] field[1] field[2] field2 field2[0] field2[1] etc
-
how can i display php source code snippets ?
mikesta707 replied to imarockstar's topic in PHP Coding Help
use html entities -
is there a PHP equivalent for the C++ friend keyword?
-
also remember that not all sites are written in purely PHP. there are many different web programming languages that people can use, like javascript, asp, RoR, perl, etc.
-
just use implode? $arr = (1, 2, 3); echo implode(',', $arr); //output: 1,2,3
-
create text boxes instead of a text area, like code <input type="text" name="sites[]" /> <input type="text" name="sites[]" /> <input type="text" name="sites[]" /> and you could have a javascript button that could dynamically add input boxes as needed, and use that
-
it seems fine. as far as mysql goes, usually you are good with mysql_real_escape_string(). you may want to add a trim for posterity, and I usually do an htmlentities rather than a strip tag.
-
what do you mean by secure? do you want to use a secure protocol like HTTPS to make sure the post data is encrypted? DO you want to sanitize the user input so you are safe from injection attacks? Security is a very broad field, so you have to be specific about what you want
-
post code. a syntax error is usually easy to fix
-
try changing this if(move_uploaded_file($_FILES['image_filename']['tmp_mane'], $ImageName)){ //get info about the image being uploaded list($width, $height, $type, $attr) = getimagesize($ImageName); switch($type){ case 1: $ext = ".gif"; break; case 2: $ext = ".jpg"; break; case 3: $ext = ".png"; break; default: echo "Sorry, but the file you uploaded was not a GIF, JPG or PNG file.<br>"; echo "Please hit the BACK button and try again."; } to this, to see if there is a problem with moving the file if(move_uploaded_file($_FILES['image_filename']['tmp_mane'], $ImageName)){ //get info about the image being uploaded list($width, $height, $type, $attr) = getimagesize($ImageName); switch($type){ case 1: $ext = ".gif"; break; case 2: $ext = ".jpg"; break; case 3: $ext = ".png"; break; default: echo "Sorry, but the file you uploaded was not a GIF, JPG or PNG file.<br>"; echo "Please hit the BACK button and try again."; } else { echo "FIle upload failed!"; exit(); }
-
if you can't understand tutorials on functions or classes, perhaps you should read tutorials on more basic aspects of PVP. classes can be somewhat hard to understand, but functions are just a couple of lines of code that you can basically run with certain information and have it spit out more information. classes are like containers that have a certain set of data, with a certain set of functions that can alter that data. what kind of breakdown do you seek. it doesn't take much real world experience to see how classes work. are you looking to be convinced that you should use classes? do you want a sample function with an explanation of every line? Also, what about the tutorials do you not understand. I have read the w3schools tutorials, as well as the manual, and it seems very clear to me.
-
corbin is right, you should definitely look into some tutorials, but about the code class myClass { private $var1, $var2, $var3; public function display(){ echo $this->var1, $this->var2, $this->var3; } }//end class this defines a class. you can define variables within the class, and set hem as private, public, or protected. private means that only the class can access them, and public means that anyone can access them. Ill explain this further with the next code snippet the function display is called a method, because its a function within the class. there are a couple of things to notice. for a class to access its member variables, we use the $this keyword, with the array (->) character. if you are familiar with C++, java, etc. it is similar to the '.' operator. calling a method is similar. we use the same $this-> syntax, but with the method name. IE $this->display() now the second snippet $object = new myClass; echo $object->var1; the first line does what is called instantiating the class. Basically it means to create an "object" of the class. That object is now a container in your code with the classes data members and methods. Look at the second line. notice two things. WHen we access PUBLIC data members and methods, instead of the $this keyword (which is only usable inside classes) we use the variable name, which is now basically a reference to the object of class myClass. The second thing to notice is that the second line won't work because the data member var1 in the class myCLass is defined as private, so only the class can use it. If we were to change the keyword private to public, than it would work in that case. but honestly, as corbin said, the subject of OOP is far too huge to cover in one simple post. I didn't even go over constructors, protected, inheritance or anything like that. I really think you should read up on some tutorials and try it yourself.
-
do you know how post variables work? if so just set the post variable to its corresponding session variable. they are both arrays, so the use is fundamentally the same. you need session_start() at the top of any page that uses the session super global, but something like $_SESSION['fname'] = $_POST['fname'];
-
well functions are incredibly useful. Even in procedural style coding, whenever you have code that is repeated, it makes your code a lot more readable, and it greatly reduces repeat code. A good example is a sanitation function. You may need to sanitize user input in a bunch of different places in your website, but instead of manually doing it every time, you can just create a function that takes an unclean string, and returns a clean one. This is incredibly useful on pages where you may need to sanitize a lot of input. classes are also incredibly useful. There are a few things you have to understand, and apperciate before they seem useful though. The main thing is encapsulation, which is basically the practice of using classes to protect your data, and put your data in a sort of "container". for sake of ease, i'm not going to go over abstraction or polymorphism and I'll briefly mention inheritance. Now here is an example (more theory than practical, but still) class myClass { private $var1, $var2, $var3; public display(){ echo $this->var1, $this->var2, $this->var3; } }//end class alright, so the first thing to note is setting the variables as private. This makes it so that only the class itself can access those variables. so doing something like $object = new myClass; echo $object->var1; will not work, and will throw a php error now why is this useful? This allows me to make sure that data that should be of a certain format, or should only have certain values does, because I take care of all that in my class. So if you were to work for a company, with several different programmers, or open source your project, programmers wouldn't accidentally give that variable bad information to screw up the entire script. A great example is the Facebook API (what developers use to make facebook applications) certain information should only be used by the class (for example, the user id of the current user) if you could change that, then you could make it appear as if a user was someone they werent! Another example is a class I built at my job. It takes a query, and some other information, and builds am HTML table of the values so that another javascript class can filter it and other stuff. Now certain things in that class just shouldn't ever be altered by a programmer that is using the class. For example, the column names (which are retrieved from the query itself) Or the data returned. Setting these data members as private ensures that no one can mess with it except for the class. Classes also help a lot with repeated code, since you can define methods inside classes. Also, because of encapsulation, we have a bunch of data that is within the scope of all the methods. In some cases, we would have functions that need (for example) 10 parameters that aren't define in the scope of the function, and we may need to set 5 other different variables. With encapsulation, we may only need 2-4 different parameters, and the rest come from the class. in a procedural script, we would need to pass the 10 parameters to use, and 5 more by reference to change. thats 15 different parameters! Now don't get me wrong. You need to mess around with OOP before you can get a sense of when to use OOP and when OOP would just be pointless. Shorter scripts usually don't need OOP, but when you have large applications that have a lot of similar data that is processed the same (and thus can be put into their own "containers" to handle the processing) OOP can become a hugely useful tool. Remember, programming is about using the tools your given in the best way. Sure a small screwdriver might be able to do the job of a large one, but using a large one results in more efficient, better applications. But sometimes using that large screwdriver is overkill. its all about the situation at hand