-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Check if a request is from curl or an actual user?
PFMaBiSmAd replied to ballhogjoni's topic in PHP Coding Help
cURL stands for - Client URL Library and the whole point of it is to be able to make requests that are identical to what a client would make. The only thing you can do is detect the information that is part of the request, such as the IP address, HTTP Request Headers, cookies/session id cookie, URL (path/page), and any post/get data. If the person using curl to make the request is doing it from an expected IP address and is supplying any expected header/cookie/token/URL/post/get values, then you would not be able to distinguish a curl request from a browser making the request. What exact problem are you having that you are trying to solve? -
What's the actual command line that you are having the scheduler execute? It would need to contain php's CLI and your .php script file name. From your other thread on this -
-
Use get_class_methods to see what methods php thinks exist for the class. You either have a spelling error, multiple include files in different folders, or the actual class that got uploaded to the server isn't the one that contains that method(s).
-
See if there are any php errors being reported. Add the following two lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(-1);
-
$_SERVER['DOCUMENT_ROOT']
-
PHP script not working but NO error messages
PFMaBiSmAd replied to Topshed's topic in PHP Coding Help
The code you posted is missing three closing }'s, which should be producing a fatal php parse error of some kind. You should have error_reporting set to E_ALL and display_errors set to on in your master php.ini of your development system so that all the php detected errors will be reported and displayed. -
inserting php variable into function attribute of form tag
PFMaBiSmAd replied to flunn's topic in PHP Coding Help
That's called pagination. It doesn't matter what the content is that you display on the page, you would still use only one actual page name and pass the desired page number as a get parameter on the end of the URL. See this link - http://www.phpfreaks.com/tutorial/basic-pagination -
inserting php variable into function attribute of form tag
PFMaBiSmAd replied to flunn's topic in PHP Coding Help
Slightly off topic, but you should not be making a series of separate pages - flash_card_1.php, flash_card_2.php, flash_card_x.php. You should make one page - flash_card.php that has a GET parameter on the end of the URL - flash_card_2.php?card=2 so that you only have one page of code to write and maintain. You can access the value from the URL using $_GET['card'] -
list($key,$value) = each($var['cc']);
-
is there a way to write a code to detect browser plugins?
PFMaBiSmAd replied to Hall of Famer's topic in PHP Coding Help
In case stating it one more time will help - -
is there a way to write a code to detect browser plugins?
PFMaBiSmAd replied to Hall of Famer's topic in PHP Coding Help
What problem? You haven't provided any information on the significance and meaning of the id and how it is related to any specific user. No one can tell you yet if using a session to hold the value will accomplish what you are trying to do because we don't know what it is you are trying to do. -
The problem is occurring in photograph.php - You are using a URL to include files. That is creating two problems. 1) Only the output from the file is being included/required, the same as if you browsed to the file, and 2) anything you define in the main file's scope, like defined constants, don't exist in the included/required file because it is being parsed and executed in a completely separate http request/process. You should be including/requiring files using a file system path, not a URL.
-
is there a way to write a code to detect browser plugins?
PFMaBiSmAd replied to Hall of Famer's topic in PHP Coding Help
^^^ See the information already stated. There's no point in trying to detect a client side tool like that because you don't need any tool other than a browser and a simple editor to see and get the HTML of the form and produce a form that has any value for any hidden field and submit it to your server. What exact problem are you having with a potential change in an id value? You should already be checking when you produce the form and when you process the form submission that the current visitor has the necessary permissions to access the specific id value, and depending on what you are actually doing, you can probably just store the id in a session variable on the server and not even pass it through the form. -
The only thing that is apparent, is that you need to escape the data before you put it into the query statement. It would help if you defined: it doesn't work?
-
Sorting Numerically and then Alphabetically in Certain Format
PFMaBiSmAd replied to abney317's topic in PHP Coding Help
By multiplying the field contents by 1, it is converted to a number and only the leading numerical value is used. <?php $query = "select dataID, dataID * 1 as ord FROM data order by ord, dataID"; $result = mysql_query($query); $heading = null; // remember last heading, initialize to a value that will never exist as data while(list($dataID,$ord) = mysql_fetch_row($result)){ if($heading != $ord){ // a new (or first) heading found if($heading != null){ // not the first heading, close out the previous section echo implode (' / ',$data) . '<br />'; } $heading = $ord; // remember new heading // start a new section $data = array(); } // handle each piece of data $data[] = $dataID; } // close out the last section echo implode (' / ',$data) . '<br />'; -
Sorting Numerically and then Alphabetically in Certain Format
PFMaBiSmAd replied to abney317's topic in PHP Coding Help
select *, dataID * 1 as ord FROM data order by dataID * 1, dataID You can detect the change in the $row['ord'] value to start a new section. -
Lengthening session with htaccess and php_value?
PFMaBiSmAd replied to Someone2's topic in PHP Coding Help
^^^ How do you know it doesn't extend the length of the session? ^^^ Have you set the session.save_path to point to a 'private' folder that is within your account's folder tree so that your session data files will only be affected by your session settings? If you are using the default shared tmp folder, the shortest session.gc_maxlifetime value of all the accounts running on that server will 'win'. Overall, why do you want to extend the session? By design it should last for the duration of ONE Browser SESSION (that's why it is called what it is.) -
Calling data from two tables and multiplying it?
PFMaBiSmAd replied to doomdude's topic in PHP Coding Help
<?php // get the ounit data $result = mysql_query("SELECT * FROM ounits") or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ $opower['ounit' . $row['ounit']] = $row['opower']; } echo '<pre>Power:',print_r($opower,true),'</pre>'; // dump the power data for demo purposes // get the member's row of data $result = mysql_query("SELECT * FROM members WHERE Username='$_SESSION[username]'") or die(mysql_error()); $row = mysql_fetch_assoc($result); // $row['ounit1'] .. $row['ounit12'] contains the member's data echo '<pre>Row:',print_r($row,true),'</pre>'; // dump the member's data for demo purposes // multiply the corresponding data together foreach($row as $key=>$value){ if(strpos($key, 'ounit') !== false){ // use only the 'ounitx' elements $arr[$key] = $value * $opower[$key]; } } echo '<pre>Mult:',print_r($arr,true),'</pre>'; // dump the multiplied data for demo purposes $total = array_sum($arr); // get the total echo "Total: $total"; ?> Edit: fixed left-over result1 in code. -
Calling data from two tables and multiplying it?
PFMaBiSmAd replied to doomdude's topic in PHP Coding Help
If your ounits table contains 12 rows, you would want to use a query that gets all 12 of those rows into a result set. I would then pre-preocess the ounits data to get the opower values into an array that has the same index names (ounit1, ounit2, ..., ounit12) as what the member $row['...'] query data will have. You can then simply iterate over the index names ounit1, ounit2, ..., ounit12 to access both the member's value and the corresponding opower value. Edit: You are retrieving only one row from your members table. There's no need to use a while() loop. Your assignment statements $row['ounit1'] = $ounit1; and $row['opower'] = $opower1; have the left-hand and right-hand side backward. -
is there a way to write a code to detect browser plugins?
PFMaBiSmAd replied to Hall of Famer's topic in PHP Coding Help
For the specific example form you posted, you should pass the minimum necessary information through it. It would appear that the id identifies the row in the database table that holds the other values. Just pass the id through the form. No need to pass the other values because you already know what they are from the id. Doing so will also mean less values to validate, less html to produce and send to the browser, less data being submitted back to the server, and less code all around. -
I'm going to guess in your actual full code, somewhere between the msyql_query() statement and the code you did post, that you have a mysql_fetch_xxxxx statement that is fetching and discarding the first row in the result set.
-
You need to put the logic that displays the data AFTER the logic that updates the data. You also need to use just one set of code that makes a connection to the database server and mysql_result is the slowest way of accessing data from a query. You should just use one mysql_fetch_assoc statement to fetch the whole row at one time instead of a number of mysql_result statements.
-
Assign random draft numbers all at once - <?php if(isset($_POST)) { $result=mysql_query("SELECT id FROM names"); // get all rows/all id's $totalplayers=mysql_num_rows($result); $available_numbers = range(1,$totalplayers); // array of all draft numbers shuffle($available_numbers); // randomize the available numbers while($row = mysql_fetch_assoc($result)){ $draft_number = array_pop($available_numbers); // pop a number from the end of the array $query = "UPDATE names SET draft = '$draft_number' WHERE id = '{$row['id']}'"; mysql_query($query) or die('Update query failed!'); } } Assign one unused random draft number to a specific id - <?php if(isset($_POST)) { $uid=$_POST['name']; $result=mysql_query("SELECT GROUP_CONCAT(draft), COUNT(*) FROM names"); // get existing draft numbers and count of all rows list($draft,$totalplayers)=mysql_fetch_row($result); $draft_numbers = range(1,$totalplayers); // array of all draft numbers $used_numbers = explode(',',$draft); // array of used draft numbers $available_numbers = array_diff($draft_numbers, $used_numbers); // determine unused draft numbers shuffle($available_numbers); // randomize the available numbers $draft_number = array_pop($available_numbers); // pop a number from the end of the array $query = "UPDATE names SET draft = '$draft_number' WHERE id = '$uid'"; mysql_query($query) or die('Update query failed!'); }
-
So, are you trying to assign a unique and random draft number to each player, all at once? Or are you trying to assign a (one) unique/unused random draft number to a player who's id is in $uid? Also, how many player names are there, because it might be more prudent to get a list of the used draft numbers up front, rather than execute a query inside of a loop trying to find an unused draft number. Edit: Unless you have thousands of players, regardless of assigning draft numbers all at once or to only one player with a specific id, it will be more efficient (because you are trying to use all the choices when you get closes and closer to the end, you will need to execute more and more select queries inside the loop to find an unused number) to get a list of the available draft numbers, randomize it, then pick a number(s).
-
If you are looping over some data, you would use a loop construct of some kind to iterate over that specific data. What's your overall code?