-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
closing the data section just refers to generating the HTML to close the section on the page holding the information. For example closing out table or div tags. An alternative way to process things is to build a multi-dimensional array out of the results. The way you do that is first decide on an array format and then choose unique values you can use to index various levels of the array. In this case your array would end up having two levels. The first level would be the orders, and the second the products associated with each order, something like: array( 'o_id' => array( // order details , 'products' => array( //list of products ) ) , //additional orders ) So to process that you need the unique values of o_id for the top level. As you loop the results you'd test if an entry for $row['o_id'] exists in the order list and if not create it, then add the product for the current row to the order indicated by $row['o_id']. Something like: $orders = array(); while ($row=$query->fetch()){ $oid = $row['o_id']; if (!isset($orders[$oid])){ $orders[$oid] = array( 'clientName' => $row['CLIENT_NAME'] , 'date' => $row['date'] , // rest of the fields , 'products' => array() //empty array to hold products ); } //Add the product to the order $orders[$oid]['products'][] = array( 'name' => $row['productName'] , 'qty' => $row['qty'] ); } Now $orders will contain a list of each order, and within each order you have the products array listing each product. You can use that to build your final HTML output: <?php foreach ($orders as $o): ?> <div class="order"> <h1><?=htmlentities($o['clientName'])?></h1> <p>On: <?=htmlentities($o['date'])?></p> <p>Products ordered:</p> <ul> <?php foreach ($o['products'] as $p): ?> <li><?=htmlentities($p['name'])?>; qty: <?=htmlentities($p['qty']);?></li> <?php endforeach; ?> </ul> </div> <?php endforeach; ?>
-
The server will generate the ETag based on various file attributes. Which attributes it considers is defined by the FileETag directive. As set in the example, it would use the files last modified date and the size of the file to generate the identifier. How it uses those values to generate the tag is up to it's implementation details. If you were developing a script that needed to generate an ETag you might use something like: $etag = sha1(filemtime($file).'-'.filesize($file)); header('ETag: '.$etag);
-
If you wanted to set it for a specific file you'd use the <Files> block to limit it's scope, eg: <Files somefile.css> FileETag MTime Size </Files>
-
The query method is part of the PDO class, which you have instantiated. That method will run the query and then instantiate a new PDOStatement object and return that back to you so that you can access the results.
-
For the most part you'll just need to do a bunch of logging of different things and then keep an eye on things manually. There isn't really any good automated method you could used.
-
You'd need to add some javascript that runs onload an inspects the URL hash value to determine which tab to open. For instance (untested): jQuery(function($){ var tab = location.hash; var $widget = $('#prod-tabs'); $widget.find('a').each(function(idx,ele){ if (ele.href == tab){ $widget.tabs('load', idx); } }); });
-
You need to do as the error message tells you. Go to http://go.microsoft.com/fwlink/?LinkId=163712 and download then install the Microsoft SQL Server 2008 R2 Native Client package. It is required for the sqlsrv driver to function.
- 2 replies
-
- php 5.3.28
- mssql
-
(and 3 more)
Tagged with:
-
Finding extension of file that has been retrieved using CURL
kicken replied to stubarny's topic in PHP Coding Help
The header name you'll be looking for would be the Content-disposition header, which takes the format of Content-disposition: [attachment|inline]; filename="the_filename.ext" (quotes optional) Using the CURLOPT_HEADERFUNCTION option may be better than having the headers included in the output and then stripping them. Creating a class to handle the download would probably make this easier as your callback can be another method and you can share data using class-level variables. This is something I've never personally tried, and the below sample code is completely untested by may get you started. <?php class DownloadFile { private $ch; private $headers; private $status; public function __construct($url, $cookieFile){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSLVERSION,3); curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'captureHeader')); $this->ch = $ch; } public function __destruct(){ curl_close ($this->ch); } public function download(){ return curl_exec($this->ch); } protected function normalize($header){ return ucfirst(strtolower(trim($header))); } protected function captureHeader($ch, $headerData){ if (substr($headerData, 0, 4) == 'HTTP'){ $this->status = substr($headerData, 9, 3); } else if (false !== strpos($headerData, ':')){ list($header, $content) = explode(':', $headerData, 2); //Normalize the header name $header = $this->normalize($header); $content = trim($content); $this->headers[$header] = $content; } return strlen($headerData); } public function getHeader($header){ $header = $this->normalize($header); return array_key_exists($header, $this->headers)?$this->headers[$header]:null; } } //Set $url and $cookie $dl = new DownloadFile($url, $cookie); $content = $dl->download(); $saveName = 'default.html'; if ($header=$dl->getHeader('Content-disposition')){ if (preg_match('/filename="?(.*)"?/', $header, $matches)){ $saveName = $matches[1]; } } file_put_contents($saveName, $content); -
You could possibly get them out of your access log using something like this: RewriteEngine on RewriteCond %{REQUEST_URI} ^[^?]*:// RewriteRule ^ - [F,L,E=nolog] CustomLog logs/access_log common env=!nolog If you're ok with just disabling logging entirely though then might as well go that route and make things easier. If you'd prefer to keep logging enabled then probably the easiest thing to do would be to just make sure you have log rotation setup and configure that as needed to limit the size of your log files and keep the disk usage in check.
-
exec is for executing an external program, not running SQL queries. When Jacques1 mentioned using exec, he was talking about the PDO::exec method. This is a method on your PDO object that is for running a SQL statement which does not return a result set. You were using this method in your procedural example. Just use it in your class as well.
-
I prefer to make PHP classes that resemble the structures/packets you'll be using to query a server. You can then either use the __toString or make a pack method that will generate the byte sequences that need sent. For example for the Source server header packet might be represented as such: class SourceHeader { public $header; public $id; public $total; public $number; public $size; public function pack(){ return pack("VVCCv", $this->header, $this->id, $this->total, $this->number, $this->size); } public static function createFromBuffer($buffer){ $fields = unpack("Vheader/Vid/Ctotal/Cnumber/vsize", $buffer); $obj = new self; $obj->header = $fields['header']; $obj->id = $fields['id']; $obj->total = $fields['total']; $obj->number = $fields['number']; $obj->size = $fields['size']; return $obj; } } Of course you'll need to add some extra code to handle things like different versions possibly returning more or less fields. For example in the above if $obj->header&0x800000 == 1 then there are two additional fields size (another one separate from the one listed) and crc32 sum representing the size and checksum of the uncompressed data. Also the size field listed may or may not exist depending on the engine and it's version. By making things classes like that though it helps keep things organized, readable, and lets you only have to mess with generating the binary strings in one place. As for the UDP sockets, you'd just create one using stream_socket_client, send data using stream_socket_sendto, and read data using stream_socket_recvfrom. Such as: $header = new SourceHeader; $header->header = -1; $socket = stream_socket_client('udp://game.server.address:port'); stream_socket_sendto($socket, $header->pack()); I've never messed with querying game servers, so I have no idea how exactly the interactions go for it. It has also been quite a while since I've done anything with UDP sockets, so the above is based on memory and a few minutes looking over the php and valve manuals. There are likely bugs that would need worked out, and definitally error handling that needs worked in.
-
The setup kind of depends on what all your hosting and how. For the wildcard subdomains you can setup a wildcard virtualhost in apache to respond, then in your code check $_SERVER['HTTP_HOST'] to determine which domain is being accessed: <VirtualHost *:80> ServerName example.com ServerAlias *.example.com DocumentRoot /var/www/example.com/public_html </VirtualHost> And in PHP: <?php //Assumes only one level list($subdomain) = explode('.', $_SERVER['HTTP_HOST'], 2); var_dump($subdomain); ?> To allow users to attach their own custom domains you'd need to add additional ServerAlias directives for each additional domain. Alternatively, if these user sites are the only thing you plan to host on the server you can just configure apache as a single-host server and point all requests to the same codebase regardless of how the request was made. Then you can use PHP as indicated above to inspect the hostname used and respond appropriately.
-
If the settings for each location and # of locations don't change frequently I would probably just make a single .bat file that they can run and just select an environment. Eg: @echo off echo [1] Site 1 echo [2] Site 2 echo [3] Site 4 SET /p LOC=Enter your location: GOTO :Loc%LOC% :Loc1 echo netsh for site1... GOTO :EOF :Loc2 echo netsh for site2... GOTO :EOF :Loc3 echo netsh for site3... GOTO :EOF
-
You don't need 50 different commands, just use some variables to enter in the appropriate information for each site. Eg: <?php $sites = array( 'Location1' => array( 'ip' => '192.168.0.2' , 'netmask' => '255.255.255.0' , 'gateway' => '192.168.0.1' ) , 'Location2' => array( 'ip' => '10.100.10.1' , 'netmask' => '255.255.0.0' , 'gateway' => '10.100.1.1' ) /// more ); //Do something to find the right settings $site = $sites[$_GET['siteName']]; $cmd = sprintf('netsh int ipv4 set address name="Local Area Connection" source=static address=%s mask=%s gateway=%s', $site['ip'], $site['netmask'], $site['gateway']); exec($cmd); You can't have it automatically change the settings of a client machine, only the server machine. If you're using a locally installed server then that'd work because the client and server are the same but if they are accessing a hosted website then the best you could do is generate a .bat file for them to download and run.
-
Yes, you'd just have to build the appropriate netsh command(s) to do what you want and then run them using exec. You'd have to make sure that the user your PHP script is being run as has the necessary permissions to execute those commands. Out of curiosity, why do you want to dynamically change your IP settings like this?
-
If you want to execute the method and return it's return value, you should use call_user_func or call_user_func_array. function __get($property){ $method = "get{$property}"; if(method_exists($this, $method)) { return call_user_func(array($this, $method)); } }
-
Editing PHP Script to Enable Parsing of Large XML File
kicken replied to maghnom's topic in Third Party Scripts
I've not used XMLReader, however one of the user comments points to a SimpleXMLReader class that provides a simple call-back style interface for parsing a large XML file. You could give that a try and see if it works out for you. As for your current file-splitting solution, so long as the file splits correctly it shouldn't cause any issues as you don't seem to have an inter-dependencies during the parsing. -
A strong hash algorithm and randomness source are your last line of defense. They come into play when the attacker manages to get access to the raw hash value from your database such as via SQL injection, direct DB access, etc. Once they have the raw hash value, all the other security mechanisms (lockout, IDS, bans, etc) become irrelevant. Just because a system has a lot of other means in place to stop an attack doesn't mean it can get away with a weak/non-existent hash algorithm.
-
PHP spl_autoload_register, spl_autoload and __autoload functions
kicken replied to Ansego's topic in PHP Coding Help
How many methods a class that gets autoloaded has is irrelevant. The only responsibility of the autoloader is to locate the class file and then include it. The main limitation of __autoload is that you can only have a single autoloader defined which is a problem if you start trying to use various libraries, each of which needs/wants to define it's own autoloader method. spl_autoload_register solves this problem by allowing you to build a chain of autoloader functions which are called in sequence until either one successfully loads the class or there are no more left to call. With this setup each of the libraries that you use can just add their own autoloader function to the chain by calling spl_autoload_register with an appropriate callback. You need an autoloader to dynamically include your classes. You don't necessarily have to create your own though. If you follow convention, then you can use the built-in one, spl_autoload, by just calling spl_autoload_register with no arguments. For most projects you'll likely be using some external libraries and an easy way to manage those is via the composer utility. If you use it, then composer will register an autoloader to load those libraries, and you can also use it as your autoloader rather than creating your own implementation.- 6 replies
-
- spl_autoload_register
- spl_autoload
-
(and 1 more)
Tagged with:
-
What seems likely is that the update query runs, but simply has no effect as the values you bind are NULL. As mentioned you limited your SELECT query to a single row (LIMIT 1) but then you try and fetch two rows ($ccheck and $cinf). Since there is at most one row, the second fetch is going to fail and result in $cinf being set to false. Since $cinf is set to false, that then means that trying to access $cinf and $cinf[quantity] is going to result in a NULL value since $cinf is not an array and that key doesn't exist. Since your $code and $quantity values are going to be NULL, your UPDATE query will effectively do nothing. What you need to do is only fetch one row from your SELECT query results, and make sure you fetch it into the correct variable. You should also being using prepare/bind for the SELECT query as well since it user parameters. You should be using prepare/bind for any query with parameters, not just an UPDATE or DELETE. $sqld = "SELECT * FROM orders WHERE `id`='$delete' AND `name`=:name' AND `email`=:email LIMIT 1"; $csql = $db->prepare($sqld); $csql->bindValue(':name', $inf2['name']); $csql->bindValue(':email', $inf2['email']); $csql->execute(); $cinf = $csql->fetch(PDO::FETCH_ASSOC); $csql->closeCursor(); //Generally optional, but I like to do it. $quantity = $cinf['quantity']; //Quote array keys $code = $cinf['code']; // " If you don't have PDO running in exception mode for error reporting, then you should also be checking the result of execute() to make sure the query was successful and if not report the error.
-
array_intersect only checks the values, without regard to which keys they are assigned. That is why you get the result you do. Array intersect works something like this: function array_intersect(){ $allArrays = func_get_args(); $firstArray = array_shift($allArrays); $output = array(); foreach ($firstArray as $key=>$value){ //Check if the value exists in the other arrays $exists = true; foreach ($allArrays as $testArray){ if (!in_array($value, $testArray)){ $exists=false; break; } } if ($exists){ $output[$key] = $value; } } return $output; } It doesn't matter which key contains the value in the subsequent array. If it exists at all then that key/value pair is returned in the new array. Essentially this means your array consists of only two elements, 'yes' and 'no', both of which are contained in the second array so you get back a copy of the first array. array_intersect_assoc will take the keys into account and as such return the proper result of nothing for your case. For each item in the original array it will check if any of the subsequent items have that key, and if that key's value is the same as the original value. As mentioned by Barand in your previous thread however, if all you want to know is whether they are the same or not then you can simply use the == operator. The array_intersect_assoc is only necessary if you need to do something with the common elements.
-
If you want to test what type an object is, you can use the instanceof operator. foreach ($my_person as $dis_array){ if ($dis_array instanceof Player){ echo "I've been a player"; } if ($dis_array instanceof Manager){ echo "I've been a manager"; } if ($dis_array instanceof Referee){ echo "I've been a ref"; } } With regard to the echo's you could just make each class return it's name via a method like getPlayerType or something: foreach ($my_person as $object){ echo "I've been a ".$object->getPlayerType(); } For the other method calls, more information about what the methods are would be needed to see if there might be another solution besides testing with instanceof.
-
Check their input using ctype_digit to ensure that what they entered is numeric. If not, re-show the form with an error message.
-
Your lines: </xsl:for-each> </property> are backwards. You should be closing the property tag before the for-each tag.
-
Removing the linkMe class will not remove the click handler you install on the element. What you should do is install the click handler on the element regardless of whether the linkMe class is present or not, but then have the handler only do something if the class is present: //Add a click handler to the navigation2 element $('.navigation2').click(function(e){ //If the element also has the linkMe class if ($(e.currentTarget).is('.linkMe')){ //Do the redirect window.location.href = 'discover.html'; } });