exeTrix
Members-
Posts
53 -
Joined
-
Last visited
Everything posted by exeTrix
-
How to unzip files on remote server using PHP script
exeTrix replied to lupus2203's topic in PHP Coding Help
I don't think it's relating to permissions because I can download the file, so we can assume the issue isn't permission related. As far as I can tell the open method requires a file that's relative to the filesystem. Basically, I don't think it allows you to open files via HTTP, FTP or HTTPS protocols because the class doesn't extend SPLFileObject. I'd suggest trying to store the zip on the server using fopen (http://php.net/manual/en/function.fopen.php) then opening the ZipArchive and clear the tmp file in __destruct method. -
Nah that won't cause the issue. I have a feeling it's something to do with the HTML file but I'll need to see it before I can say 100%.
-
Ok I'm at a loss here... Please post all your source code so I can see the pages and markup. From the information given in your first post I can't see why telephone number is being omitted. You don't have intersecting forms on the HTML page do you?
-
Wow that regex is mental. Reminds me of spagetti letters I think it can be simplified to this. Give it a try this, you might have to tinker with it as I have no method of testing. Just make sure this code is at the top of every file ( by this I mean in an included file ) and not output is place in the buffer before Header() is called. $userAgent = $_SERVER['HTTP_USER_AGENT']; if( preg_match( '%(iPhone|Android|webOS|BlackBerry|iPad%i', $userAgent){ $domain = str_repace( 'www.', $_SERVER['HTTP_HOST$_SERVER'] ); Header( 'Location: http://mobi.' . $domain . $_SERVER['REQUEST_URI'] ); }
-
@eldan88 because you're doing a string comparison make sure there aren't any characters in the name which could be getting encoded when sent via GET.
-
domdocument removeChild getting inconsistent results
exeTrix replied to rwhite35's topic in PHP Coding Help
You're a brave man approaching DOMdocument. I've seen it chew and spit out many developers in the past. You'll have to excuse me, but I've limited experience with DOMDocument I've avoided it like the plague and used SimpleXML in the past $pnode = $xml->getElementsByTagName('blog'); foreach($pnode as $key){ //outter loop thru parent nodes foreach($pid as $v){ //inner loop thru pid array if ($key->getAttribute('id')==$v){ $oldxml = $tempxml->removeChild($key); } } } Try the above to see if that makes any difference. My concern is you have a few objects there that are independent of one another. So we'll refine down until the issue becomes clear. -
mysql error on re-load - perhaps pass values through hyperlink
exeTrix replied to davidcriniti's topic in PHP Coding Help
The structure of your link is incorrect. Should be: echo "<a href=\"course_display.php?link=2&course_id=". $course_id. "&course_password=" . $course_password . " \">Instructions</a><br />"; When constructing a URL you need to have the page, in this case course_display.php then a question mark to start the get key value pairs so now we have course_display.php? next add the key value pairs with no spaces course_display.php?link=2&course_id=1&...... -
Did you miss the ;
-
POST Method. Post javascript to php script
exeTrix replied to davefootball123's topic in PHP Coding Help
Not really a PHP question more JS/jQuery but I'd use: $.post({ type: "POST", url: 'http://fqdn.com/script.php', data: { lat: 3623767534757634657345734567345765367, long: 5847589534534653753476536575 }, success: function( resp ){ //do something here to inform the user everything is hunky dori }, dataType:'json' }) -
I've just tried to get the feed on my machine and the file is loaded fine. One thing I noticed is that the http://search.popurls.com/rss/apple is displaying the page with HTML. If you have control of that page then set the headers etc to XML. Could you post the source so we can assist you?
-
@webdesignwhitey there's something missing here... I can't see any reason for the error to be triggered. Everything looks fine. Please put print_r( $_POST ); at the top of the sendEmail.php file and let us know the output. Better yet, upload the files as they stand at present so I can see their structure.
-
Help needed - Dropdowns Form to create URL
exeTrix replied to CapsuleCalum's topic in PHP Coding Help
Urgh Roman cart.... you could user urldecode. This should get it working $buildURL = 'http://www.romancart.com/cart.asp?storeid=28254' . urldecode( $style ) .'%20'. $colour .'%20'.$size; -
yup, that'll be the reason.
-
Just looking at the code above you don't need: $func_get_args = func_get_args(); Why not do this: $argsCount = func_num_args(); if( $argsCount > 1 ){ $column = func_get_args(); } By any chance are you unsetting $column[0] later in the script which would cause the element at offset 0 to be remove, hence the array keys starting from 1?
-
I'm sorry but that's rather irritating. I have taken the time to do the above for you and you quite clearly having read or bothered to understand what's going on. Stop copy and pasting and attempt to understand, if you don't want to learn then get a freelancer.
-
That's not a problem and don't worry OO will come in time. I remember when I was trying to get my head around it nightmare but so useful when I did! The reason behind calculateBhp being defined twice is just to illustrate inheritance. Lets say that all manufacturers calculate BHP in the same way, however, Honda use a slightly different calculation for their cars. So rather than making a new method with a different name we just override the functionality in our child class. Inheritance is about sharing common application logic with child classes. Moreover, having the same method name means that you don't have to know which manufacturer you're dealing with in order to call the different method names. In the case of the example above it's very simple and doesn't really show object being generated dynamically. If we were getting the manufacturers from a database result set then you can see it a little more clearly: <?php //this is our fake result set $cars = array( 0 => array( 'make' => 'Honda' ), 1 => array( 'make' => 'Ford' ) ); class Car{ public $make; public $engineSize; public $doors; public function calculateBhp(){ return 90; } public function getMake(){ return $this->make; } } class Honda extends Car{ public $make = 'honda'; public function calculateBhp(){ //different logic to work out bhp return 100; } public function getMake(){ //here we're calling the method in Car which will return Honda $str = parent::getMake(); //now we're just appending a space then the engine size return $str . ' ' . $this->engineSize; } } class Ford extends Car{ public $make = 'ford'; } //now we spin over the $cars array foreach( $cars as $car ){ //now we don't know what the manufacturer is, we could put some if statements in but that'd be lame //alternative? do this $make = $car['make']; $carObj = new $make; echo $carObj->getMake() . "<br />"; echo $carObj->calculateBhp() . "bhp<br />"; } That should return the following: honda 1.4 100bhp ford 90bhp As you can see the same method has been called on both objects but you get different results. Inheritance is extremely powerful, and I use it constantly in my day job to share code between different objects.
-
It depends how you plan to spin over the array. you'll be able to use a foreach loop but anything that requires keys to be referenced like for loops you'll have to change the starting offset. Here's some examples: $array = array( 1 => 'first', 2 => 'second', 3 => 'third' ); foreach( $array as $element ){ echo $element . "<br />"; } //prints first second third //or we could reset the keys then iterate $array = array_values( $array ); $count = count( $array ); for( $x = 0; $x < $count; $x++){ echo $array[$x] . "<br>"; } //or if you want to be a right geek $iterator = new ArrayIterator( $array ); while( $iterator->valid() ){ echo $iterator->current() . "<br />"; $iterator->next(); } As for why element 0 wasn't used I'm not sure... Default behaviour in most languages when it comes to arrays is to start from 0.
-
This one is a massive topic. Just to extend upon what AK has said: 2. Another point worth mentioning here would be that storing other information when a user successfully logs in can protect against session hijacking such as IP and browser information. These come with their limitations and it'll never be full proof due to HTTP connections being stateless ( request -> response done ). Anyway, you could store the logged in users IP then compare this IP every time the user visits a secure page, this will prevent session hijacking, but if it happens in the same building behind NAT you're screwed. 3. I'm not sure how salts prevent brute force I'll have to look into that one, however, they certainly prevent rainbow table I've read that somewhere before. Essentially, with salts you're protecting users passwords if your security is compromised and allowed some naught boy/girl access to your users passwords. Another thing to bear in mind is CSRF. Without some mechanism in place to verify that the AJAX request was indeed sent from a page on your server it would leave the login entry point open to brute force attacks. Normally this can be plugged with some random string imbedded into a hidden field which is submitted with the username and password. If you're really concerned about security then one of the simplest solutions is to implement an SSL cert so all requests run over HTTPS, man in the middle see ya later. Hope that helps
-
I think you're missing the point, we're not here to complete your work for you but assist as best we can with specific problems you may encounter. I don't mean to sound brash but I don't want to have to download a project, import a database etc etc and work out what should be done for you. Ask questions and we'll be happy to help.
-
Not sure what you were doing there mate, think you need o lay off the crack but this should work. Not tested <?php $sql1= mysql_query("SELECT * FROM cart where cart_id='".$cid."' AND product123 !='' ORDER BY id DESC "); while($row1 = mysql_fetch_array($sql1)){ $price = $row1['price']; $product = $row1['product123']; $id = $row1['id']; $qty = $row1['quantity']; $category = $row1['category']; if($category="artist"){ //add the tax, you guys are lucky only getting charged 7%!!!!! $price = $price + ( $price * 0.07 ); } $price1 = $price * $qty; $total = $price1 + $total; } ?>
-
Ok, that code as a number of duplicate checks which are redundant. What I'm going to suggest should NOT be used in a production environment, however, due to you being new to PHP there's no point in me throwing information at you that you're going to struggle retain/understand. We all learnt to walk before we learnt to run... unless you're a freak of nature form.php - really simple, just a form that sends data via the POST method to a script called process.php <html> <head></head> <body> <form action="process.php" method="post" > <label for="email">Email</label><input type="text" name="email" id="email" /><br /> <label for="comments">Comments</label><textarea name="comments" id="comments"></textarea><br /> <input type="submit" /> </form> </body> </html> So when a user hits submit they'll land at process.php lets define the logic behind that: <?php //when submitting a form via the POST method (defined as one of the form attributes) we will use the $_POST superglobal to get the values entered by the user on the next page //first lets check to make sure we even have the values to begin //empty will first check to make sure that the variable exists, then it will make sure it has a none empty value //from memory empty values are: 0, "0", null, false //notice the || this means if email is empty or comments are empty execute what's between { } if( empty( $_POST['email']) || empty( $_POST['comments'] ) ){ //anyway if either of the above are empty then send them back to the form header("Location: http://yourdomain.com/form.php"); //exit is here to make sure that the rest of the page doesn't execute exit; } //now we know we have valid values (I use the term valid extremely loosly) we can continue $email_subject = 'Questions form'; $email_to = 'you@yourdomain.com'; $email_from = $_POST['email']; $email_message = $_POST['comments']; $headers = 'From: ' . $email_from . "\r\n" . 'Reply-To: ' . $email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //ok so we've assigned our POST data to some variables and generated some headers $response = @mail( $email_to, $email_subject, $email_message, $email_headers ); //now you might be thinking what's the @symbol all about? It basically supresses nasty fugly error produced when mail fails for whatever reason //also notice how we've done $response = @mai... this is because mail will return a boolean value (true/false) //to let the scriptknow if errors were encountered or not. This is good for testing the response if( $response === true ){ echo "Shazam email sent holmes" }else{ echo "Aww snap, failed to send the email. Please try again." } I've left out the html stuff on the second page, but that's about the long and short of an insecure crude email sending facility. Further reading: Cross Site Request Forgeries Hope that helps, give me a shout if you have any further questions.
-
This is purely from memory but if you wanted to add more fields you could do this with some sort of client side script to make it a bit more seamless: <input type="text" name="input[]" /> <input type="text" name="input[]" /> Then in PHP: //below should return an array with both values of the input print_r( $_POST['input'] );
-
Is either if statement "neater" or more legible than the other?
exeTrix replied to MySQL_Narb's topic in PHP Coding Help
@kicken I agree with you on that one, and it seems to be used most in WordPress themes I've noticed There are a few ways we can declare if and else statements which hasn't already been mentioned: //horrible way which turns my stomach to see if( $foo ) echo $bar; else echo $fooBar //shorthand version which is nice to use in methods class User { isLoggedIn(){ return ( $this->loggedIn ) ? true : false; //obviously we could just return the property but just illustrating the point } } -
Also exceptions built in That's a big advantage
-
@jacko_162 Well spotted! It's always good when you get to the bottom of an issue. Well done mate. @DavidAM As Jessica pointed out I was responding to the original response, I was just slow on the uptake. You are right in the majority of what you've said. However, I'd just like to point out that you've inadvertently given some incorrect advice, which could lead people new to PHP into a false sense of security (no pun intended ). PDO::query() will NOT escape data, running a statement in this way would be equivalent to mysql_query(). Therefore, you will need to escape data when using this method. Taking all arguments aside valid or not, PDO is the recommended method for database connection by PHP, so surely we should give people with less experience than us advice to change? Anyway, as long as all queries are prepared and executed then I'd be inclined to disagree that PDO will not provide a more robust protection because it eliminates human error. For example, above jacko han't escaped variables that he believes will yield an integer value from the API, I realise that maybe you can trust the response but I don't trust any values unless they're created by me. So using mysql_query() security hole PDO::prepare()->execute() hole plugged.