-
Posts
5,450 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
if you are seeing no errors, it could be because you are doing a redirect on the page and you have php's output_buffing on, either in your code or in your php.ini and any error output was discarded due to the buffing/redirect. also, the global $conn_mysqli; statement, where you are making the database connection at, doesn't do anything (well it does, by wasting your time typing that and wasting some time when the code runs.) the only place the global keyword does anything is inside of a function definition, and even there you should not use it, since it breaks the black-box model for function definitions. you should pass ALL external values into functions as call-time parameters.
-
there already is a feature like this. when you hoover over the listing of a thread, there's a black circle with a down-arrow in it, and the title text of - Preview This Topic. clicking on the black circle alternates between revealing and hiding both the first topic in the thread and the latest replies in the thread. and moving this topic to the phpfreads.com Questions, Comments, & Suggestions forum section...
-
the email is not being sent From: the email address that the visitor entered. it's being sent from your mail server at your web hosting. in this case you are trying to send it to a major mail system, gmail, and gmail checks that the From: address the email says it is from, actually corresponds to the sending mail server. you must use a from address in the email that's either hosted at the sending mail server and has a domain that can be matched to the sending mail server and/or you must have an SPF record where the domain in the from address is hosted at that says the sending mail server is authorized to send email for that domain.
-
you would need to post your actual code that produces/reproduces the problem. i suspect you have a line like - global $_SESSION; in your function, that actual breaks the connection with the actual super-global $_SESSION variable. require/include files are not pages. web pages are only the main files that get requested via their url.
-
by storing the 'NEW' value in with the data, you will have two problems - 1) this can only be used by one visitor to your site. when the 'NEW' values are cleared, due to that one visitor viewing the entries, no other visitor will ever see any bold entries. you must store the value that tells your code what has been viewed or not, separately for each visitor. 2) by not using the id of the highest row at the time you displayed the data, you can have a race condition where new entries can be inserted at the same time you are getting and display the data, that won't be displayed on that visit to your page, and that your display logic will clear the 'NEW' value for. they will be displayed the next time you visit the page without being in bold, but they are new rows that where not displayed the last time you visited the page. edit: also, your 'css' isn't css. you are using in-line styling and typing it for each element you are styling. to use css, you define styling rules, that you then apply to elements on your page using a selector, typically a class selector, so that multiple same elements can be styled without repeating the actual styling every place it is used. this allows you to make a change in one place, rather than to go through all your code and change every instance of the in-line styling. it also reduces the amount of markup and clutter you have in the code on your page.
-
your code does not address underflow/wrap-a-round and will throw this error any time it is run on a Sunday. on Sunday, date('w') produces a zero. you would need to detect that and insure that your code ends up accessing $array[6] corresponding to Saturday.
-
it depends, as CroNIX stated, on what information you are displaying. but it's the highest id of the data you are displaying, at the time you displayed it. it's not the highest id in a table because the number of rows in the table are changing asynchronous to your process where you are trying to find newer rows to display. in whatever data you are retrieving and displaying, find and store the highest id present in that data, either store it in a session variable, in a column in the user's row in a database table, or even in a get parameter in a link, whatever is appropriate for what you are doing, so that you have that value on the next page request where you want to find and display newer rows then what were displayed on the last page request.
-
A Novice Web owner needs Help with ajusting this script & testing.
mac_gyver replied to IvanTW's topic in Third Party Scripts
php is a web server-side scripting language. the php code gets parsed, tokenized (converted to tokens/bytecode), and then interpreted by the php language engine on the web server when the .php page gets requested by the browser. you would enter the url of the web page in your browser's address bar. opening/running the file directly in your browser would just show the raw php code that's in the file. if you are editing this on your local computer and want to run it locally, you would either need to have a web server installed (there are all in one LAMP/WAMP - Lunix/Windows Apache, Mysql, Php packages) or in a pinch, you can use php's built in web server - http://php.net/manual/en/features.commandline.webserver.php you can also put the code into it's own .php file on the live web server where your site is hosted at and run it there. you don't need to set the $_POST variables. there will just be empty values where they are used, but you may get php errors in their place, depending on the php error reporting settings.- 4 replies
-
- auto email
-
(and 2 more)
Tagged with:
-
A Novice Web owner needs Help with ajusting this script & testing.
mac_gyver replied to IvanTW's topic in Third Party Scripts
you can run the code in a 'test' setting, where you comment out the mail() function call and echo the $body variable see how the html will be rendered in a browser. you can either make a corresponding 'test' form to submit to it the code or simply assign values to the $_POST variables that the code expects as input.- 4 replies
-
- auto email
-
(and 2 more)
Tagged with:
-
you will need to pass the search term as part of the pagination links. if you do an advanced search on the forum (the white star/snowflake thing to the right of the search box) and search for http_build_query and my username as the 'find author', you will find a number of examples showing how to combine search terms and pagination links. http_build_query() lets you build the query string part of url's based on an array of data (the $_GET array can be used as the input array to the function.) this lets each separate part of your code, the search and the pagination, to manage just those parts of the array they are responsible for and the links will have the combined result from all your code.
-
sorry to blast away at your code, but it contains a huge security hole, in that you are putting the user_id from the database into a cookie. this will let anyone impersonate any user and modify that user's data, simply by setting the cookie to any value they want. the only place the user_id should exist at is on the server. your login system should set a session variable with the user_id. if you want a cookie, as a longer term/remember me, login, you should generate a unique and hard to guess token value, and store that in the cookie and in the user data in the database. next, you have a lot of repetition in your code, making it harder for anyone to see what the program logic actually is, which i suspect may be (didn't actually copy the code to check) why part of it is not running. your html document should only be defined once, near the end, after a majority of the php program logic. all the php form processing logic and any database logic should be near the start of your file and should contain no html markup.
-
your function definition is using $scores as the parameter variable name. your switch() statement is using $score if you set php's error_reporting to E_ALL and display_errors to ON in your php.ini, php would have been throwing an undefined variable error at the $score usage that would have pointed you toward the problem.
-
you need to store the id of the latest displayed information, so that you can query for new information with id's greater than that stored value on the next page request. for a value that needs to persist, even if someone logs out, you would need to store it in the user information in a database. see the following posts and the threads they are in for some discussion about this - http://forums.phpfreaks.com/topic/294082-highlight-newest-post-between-refresh/?do=findComment&comment=1503553 and http://forums.phpfreaks.com/topic/292925-if-mysql-table-updated-since-page-load/?do=findComment&comment=1498777
-
rather than to try and detect every 'bad' thing, current and future, because you will probably leave something out (hackers have huge libraries of exploits), you should instead validate that data only contains values with the format that you expect for that particular type of data. in those cases where the format of data can contain legitimate characters/keywords that could also allow xss or sql injection, a forum post, usernames, ... as examples, the correct way of handling those are to make those characters/keywords completely inert. to prevent xss, you would output content to the browser by passing it through a function like htmlentities. for sql injection, you would escape string data or use prepared queries when using the values in sql query statements.
-
the php.net documentation is the source documenation for all of php's features and functions - http://php.net/docs.php
-
logged in users add,edit and save text file in php
mac_gyver replied to Rubankutty's topic in PHP Coding Help
where exactly did you get stuck at when you tried to define and then do this assignment? have you defined the user interface for each of the operations? have you prototype'd the html that would be needed for each part of the user interface you have defined? have you defined how you are going to store the information in the file (note, it will be much easier and require less code if you use a database)? have you attempted to write the php code that would retrieve the data needed to produce each part of the user interface on each page and process any form submissions from those pages? -
i'm going to guess that in your php code, you are fetching and not using the first row from the result set, before the start of a loop that gets the remaining 4 rows from the result set.
-
How do you detect the outside scope of a block?
mac_gyver replied to Monkuar's topic in PHP Coding Help
the $grid in this example code, since is shows what blocks are occupied, would need an entry for every block that's occupied by an item, which is why the id of the instance of an item is what's stored. at some point, for the simplest test_pos() code, the items stored in the grid would need to be expanded and occupy all the blocks they, well occupy. -
How do you detect the outside scope of a block?
mac_gyver replied to Monkuar's topic in PHP Coding Help
your test case has no overlap. the existing item in the grid is at x=1,y=2 and has w=1,h=1. the item you are testing by calling the function starts at x=1,y=3 and goes to x=5,y=7. y=3 (the lowest y position of item being tested) is greater than y=2 (the y position of the item already in the grid) and there is no overlap. -
How do you detect the outside scope of a block?
mac_gyver replied to Monkuar's topic in PHP Coding Help
the program logic would be - // origin is top, left - 1,1 (x,y) // define grid size $max_x = 5; // across $max_y = 4; // down // create empty grid - $x = range(1,$max_x); $y = range(1,$max_y); $grid = array(); foreach($x as $xx){ foreach($y as $yy){ $grid[$xx][$yy] = 0; } } // for any requested x,y position, determine if the $item can be placed starting at that position in the grid // inputs - $x,$y - requested position // $item - item definition array(id, width, height) // $grid - the grid holding existing items // processing - test starting at the requested position if the item fits within the grid boundary and that all the corresponding cells are empty // return - 1 if the item can be placed at the requested position, 2 if out of bounds, 3 if overlap another item define('POS_OK',1); define('POS_OUTOFBOUNDS',2); define('POS_OVERLAP',3); function test_pos($x,$y,$item,$grid){ $w = $x + $item['w'] - 1; // highest width $h = $y + $item['h'] - 1; // highest height // check if out of bounds if(!isset($grid[$x]) || !isset($grid[1][$y]) || !isset($grid[$w]) || !isset($grid[1][$h])){ return POS_OUTOFBOUNDS; } // check if overlap for($xx = $x; $xx <= $w; $xx++){ for($yy = $y; $yy <= $h; $yy++){ if($grid[$xx][$yy] != 0){ return POS_OVERLAP; } } } return POS_OK; } // example usage - $item = array('id'=>123,'w'=>2,'h'=>1); // define a 'test' item $grid[5][4] = 456; // put an item in the grid (value is the item's id, 0 = empty, not used as an id value) var_dump(test_pos(3,4,$item,$grid)); -
in the posted code (reply #6), the only place the q= parameter is used is in the 'book now' link. it's not used in the curl request, which is just getting generic hotel information based on the hotel_id. the posted code is require'ing two other files. i'm going to guess that the 'files/hotel_list_page_form.php' code could contain the form/links/filters that picks/submits the url query string values you are seeing or that there's some other page on your site, before the one where the posted code is at, that's responsible for generating the url query string values. are these links actually a problem or are you just responding to what some tool is reporting? a problem with changing your code from passing this information through the url, to passing/recreating the information behind the scenes, is that someone cannot book-mark a link on your site and return later to the same place or share that book-marked location on your site with someone else. though, that brings up a question, a tool like you are using should not be submitting forms. this seems to indicate that somewhere on your site, you have a link that already has this information in it, that the tool simply found by looking at the html source. do you have links that show 'example' rooms w/options that the one you are showing us in the thread is case of or do you have simple links that when followed cause code on your site to retrieve 'example' rooms that then have the url query strings you are showing us?
-
Knowing where you are in a non-numeric index loop
mac_gyver replied to Strahan's topic in PHP Coding Help
there's no need to ever extract/manipulate form field names this way. just use an array name for each different meaning form field and you will directly received arrays of data in your php code when you add more of the same meaning form fields. -
Form form field content dropped with larger file uploads
mac_gyver replied to callerpatty's topic in PHP Coding Help
even if you change the settings, your code must ALWAYS test if the upload worked without any errors before trying to use the uploaded file information. -
after adding isset($_get pagination not working
mac_gyver replied to hakim's topic in PHP Coding Help
the php database functions you use must all be from the same library of functions, PDO in this case, to match your database connection code. if the mysql_ functions are not throwing errors, it's likely that your system has set default connection credentials that the mysql_ functions are using to make a connection. next, your code should only have two database queries in it, not three. the first query should get a count of matching rows and the second query retrieves the rows that correspond to the logical page that was requested. the count query should be near the start of the code, not near the end, so that you can limit the logical page number being requested. both of the database queries need the same WHERE clause in them, so that they match the same set of rows (or no WHERE clause if you want to match all the rows.). if there is a $_GET['cat'] value, you need to form the WHERE clause in a php variable and put that php variable into both of the database queries (for the case of no WHERE clause, just initialize the php variable to an empty string and still put it into both queries.) all the pagination links and the form to enter a specific page number need to also propagate any $_GET['cat'] value so that it won't be lost between pages. though, your category search form/links should not propagate the page number (if you select a different category, you would want to default back to page 1.) you are not using prepared queries correctly. a prepared query uses place-holders in the sql statement where data values belong, then you bind the data to the place-holders. edit: lastly, this is more of an organizational point, but it will make writing, testing, and debugging your code easier, with less actual code. you need to separate the php business logic, that determines what to do on the page, from the presentation logic, that outputs the html document. the php business logic would perform initialization, process any post method forms, then do any processing for a get request for the page. the end result of the business logic would be php variables (usually arrays) that the presentation logic would simply test/loop over to output the content on the page. the business logic would contain all the database specific statements and it would contain no html markup. the presentation logic would not contain any database specific statements and it would contain all the html markup.