-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
try echo $doc->saveHTML($doc->documentElement));
-
Make sure your connection to MySQL is set to UTF8 as well. mysql_set_charset
-
Checking referrer when downloading from remote source
kicken replied to dannyb785's topic in PHP Coding Help
The way you prevent direct downloads is by not allowing them. That's it. You force people to access the files via your script and provide no alternative means what-so-ever for them to access the file. Generally you place the files somewhere that they will not even be served by apache at all and only your script can access them. The only possible alternative that would allow you to use a direct URL while keeping people from re-using it would be to setup a system where the direct url is constantly changing. Then you need some way to keep both your servers up to date on what the current URL is. The url's should be generated randomly, not based on some varying value like a timestamp otherwise someone could just guess. -
Try with utf8_encode, but do not decode it later. The browser will do that when it displays it.
-
Checking referrer when downloading from remote source
kicken replied to dannyb785's topic in PHP Coding Help
Despite them being spoofable, some browsers, firewalls, or proxy's will filter out a referrer for privacy reason so it will never be sent. This means your download script will not work at all for any of those people. There's not really any good way to do what you want to do when using a simple header redirect. If only logged in users should see them, then you should be running entire download process through your script rather than redirect to the raw file. -
Use cURL and set the CURLOPT_SSL_VERIFYPEER to false.
-
This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355311.0
-
The DATE, DATETIME, and TIMESTAMP Types Basically, a DATE type is just the day without any time component. A DATETIME include a timecomponent as well. Both of these types are stored in a manner that gives them a large range of values. Neither of these types are altered in any way by a timezone setting A TIMESTAMP is equivilent to a unix timestamp value and it is altered by timezone settings. Unix timestamps are the seconds since Jan 1 1970 @ midnight, UTC. As such whenever you try and convert a date/time value to a unix timestamp (such as with strtotime) the date is first converted to the UTC timezone and then the seconds returned. When you format the date, the offset of the current timezone is applied, then the date is formatted. This makes timestamps useful as you can just alter the current timezone to convert a date between timezones. You can handle this using DATETIME as well though, fairly easily even with php's [m=class.datetime]DateTime class[/m] PHP's strtotime will understand the default format they are returned in. You can however use mysql's DATE_FORMAT() function to put them into whatever display format you want from within the query and not have to bother with it in PHP. Doing things within the query when possible is usually most effecient.
-
as far as I know it's always been text/html output. There used to be a tab at the top that let you switch between html or plain text and that seems to be gone now. Maybe it remembered your selection so it went to plain text for you by default, not sure if it did that or not.
-
google image search for variations on the term hand icon brings up a few options such as Spend some time with various terms, probably find something you can use.
-
http://codepad.viper-7.com/N4SqUv You should put it in plain text mode when you test things by sending the appropriate header.
-
As far as PHP knows or cares, your query is just a string, and the string "time()" has no special meaning. As far as MySQL knows or cares, your query could have come from anywhere and it has no idea wtf time() is so it throws an error. So yes, in your SQL querys you have to either a) stick to MySQL's functions or b) break out of the string and use the concatenation operator to insert the results of calls to PHP functions. You should store a date that is in the proper format for MySQL to understand it as a DATETIME or TIMESTAMP column value. When you store a date as one of those values, then mysql knows how to handle it correctly and will allow you to do math or other operations on it easily. If for some reason you can't / won't store it as a DATETIME or TIMESTAMP, storing as an INT, using the standard unix timestamp format (seconds since epoc) is your next best thing as you can still do math with it pretty easy and it is fairly well supported. What you should pretty much never do is store a string representation of a date in a VARCHAR column (ie, '5/2/2012'. MySQL has no idea how to handle that and it just makes you have to work harder to do anything useful with it.
-
Because of Operator Precedence. The . (concatenation) and - (subtraction) operators have the same precedence level and are processed from left-to-right, so when php sees that line it does these steps: (assume time() returns 1234567 and $lastActivity contains 654321) '<p>Seconds Active: ' . time() Result: ''<p>Seconds Active: 1234567 ' [*]''<p>Seconds Active: 1234567 ' - $lastActivity Result: -654321 [*] -654321 . ' seconds</p>' Result: '-654321 seconds</p>' By either enclosing the math operation in parenthesis or moving it out to it's own line and saving the result to a variable, you force that to come first before the concatenation operations.
-
There are a couple benefits to using a flag vs calculating the value each time. 1) It can be indexed to improve query speed. Not needing to calculate it every query would also be a plus. 2) It can simplify your queries and PHP code by not having to have logic to determine online/offline scattered in them 3) It gives you a central place to adjust the timeout if you decide to raise/lower it For example re-writing your query for comments: $sql = 'SELECT u.user_id, u.user_name, c.comment, c.date_posted, u.logged_in FROM comments c INNER JOIN users u ON u.user_id=c.user_id WHERE article_id=333'); $comments = mysql_query($sql); while($row = mysql_fetch_array($comments )) { echo $row['user_name'] . "(". ($row['logged_in']?'Online':'Offline') . ") said: " . $row['comment'] . " on . " $row['date_posted']; } or without the flag and just using the activity field: $sql = 'SELECT u.user_id, u.user_name, c.comment, c.date_posted, CASE WHEN DATE_ADD(u.last_activity, INTERVAL 5 MINUTE) > NOW() THEN 1 ELSE 0 END as logged_in FROM comments c INNER JOIN users u ON u.user_id=c.user_id WHERE article_id=333'); $comments = mysql_query($sql); while($row = mysql_fetch_array($comments )) { echo $row['user_name'] . "(". ($row['logged_in']?'Online':'Offline') . ") said: " . $row['comment'] . " on . " $row['date_posted']; } Granted for a small site, any of the methods would work fine. On a larger site or active site such as a busy forum, it would likely be worth while to add a logged_in type field and modify it with a cron each minute or two to keep your queries simple and quick.
-
ensuring there is input in at least 1 of 2 fields
kicken replied to peppericious's topic in PHP Coding Help
A text field is always set, as defined by isset(), even if it's empty. You can use the empty function to check that it is set, and has a non-false value. -
You can have a flag field in your database indicated if they are logged in or out (though it's not strictly necessary). You can update it either via a cron job or via an action on each page load (regardless of who did it). I tend to do something like that by just putting a query for it in a common include file so it is run on each page load. The query would be something fairly simple like: UPDATE users SET logged_in=0 WHERE logged_in=1 AND DATE_ADD(last_activity, INTERVAL 5 MINUTE) < NOW() That will find any logged in users who have not had activity in the last 5 minutes and mark them as logged out.
-
Every user has their own unique $_SESSION variable. It is not shared between everyone on the site. The only way someone would be able to see someone else's $_SESSION data is through a method known as Session Hijacking which you can take measure to prevent such as verifying IP and Useragent strings.
-
inside your getTitle function this is the window object, not your div. You need to pass in your div as a parameter if you want access to it. <div class="container" onclick="getTitle(this);"> function getTitle(div){ //$(div) and so on }
-
You either typed in that URL, or you have some sort of redirection that is causing all the extra slashes to be added. Possibly a loop in a rewrite handler?
-
The return value is the length of the generated string. "1.2" has length=3
-
Bootstrap is refers to the startup process. It encompasses everything you need to do just to get a system up and running, before you actually start processing anything. This is things like including any necessary classes, setting up your database connection, starting up a session, etc.
-
RewriteCond %{QUERY_STRING} team_id=([0-9]+) RewriteRule ^team-info.php$ team/%1? [R=301,L] Try that.
-
The path used by RewriteRule does not include the query string. You have to test that in a RewriteCond directive. RewriteCond %{QUERY_STRING} team_id=([0-9]+) RewriteRule ^team-info.php$ team/%1 [R=301,L] I believe that would be what you want.
-
usort is a function which will sort your array by comparing the items using a custom defined function. As PHP goes through the array it will call your function several times, each time giving it two different items of the array. What your function has to do is determine how they relate to one another and return a value that is either: < 0: meaning that the first item come before the second = 0: meaning that they are equal and the order does not matter. > 0: meaning that the second item comes before the first item. So for the comparison function we have: function sortOverall($a, $b){ return $b->overallPoints - $a->overallPoints; } Let say for the first round PHP calles that with $a being: SimpleXMLElement Object ( [played] => 2 [won] => 1 [drawn] => 0 [lost] => 1 [overallpoints] => 3 ) and $b being: SimpleXMLElement Object ( [played] => 6 [won] => 3 [drawn] => 0 [lost] => 3 [overallpoints] => 9 ) For the return value we have $b->overallpoints - $a->overallpoints = 9 - 3 = 6. Since 6 is > than zero, PHP will sort them as [$b, $a], putting $b first. Then on the next round we get $a=: SimpleXMLElement Object ( [played] => 6 [won] => 3 [drawn] => 0 [lost] => 3 [overallpoints] => 9 ) and $b= SimpleXMLElement Object ( [played] => 0 [won] => 0 [drawn] => 0 [lost] => 0 [overallpoints] => 0 ) The result from the sort function is -9, which results in $a coming before $b in the final array. This process continues until the array is fully sorted. If you want to know more about how the sort is actually done, php used the quicksort algorithm which is one of the most common generic algorithms.
-
How to get the time the file was last modifed at in a PHP script
kicken replied to APD1993's topic in PHP Coding Help
Look at the highlighting in your previous post. Your missing a double-quote.