Jump to content

thebadbad

Members
  • Posts

    1,613
  • Joined

  • Last visited

Everything posted by thebadbad

  1. The BOM is a character at the very start of the document used to identify the document's encoding as UTF-8/16/32. It's not needed however, so I never include it in my documents (in Notepad++ you can choose the format "UTF-8 without BOM"), because of all the problems it could and will make eventually Use a HEX editor to see the BOM, and remove it that way if you don't use Notepad++. To tobylechein: Maybe you can solve this by choosing "UTF-8 without BOM". It's at least possible in version 4.1.2 I'm using.
  2. If you are saving your file in UTF-8 encoding, it could be the BOM (Byte Order Mark).
  3. A rule of thumb: When dealing with files online, ALWAYS stick to lowercase filenames, without any strange characters like the space. I only use letters from a-z, "_", "-" and/or periods in my filenames.
  4. That depends on what you want to do with the data. If you want to redirect it along, you should look into sessions, which can store data temporarily (and thus across pages, not depending on forms and text fields). In your example you could store the form data in sessions, like this: page_in_between_2_and_3.php ... <?php // storing the given name from page 1 and 2 $_SESSION['givenname'] = $_POST['givenname']; // storing the surname from page 2 $_SESSION['surname'] = $_POST['surname']; ?> ... And you will then be able to extract the data again on whatever page you like, like this: <?php echo $_SESSION['givenname']; ?> I recommend you to read this short article on sessions: http://www.tizag.com/phpT/phpsessions.php, because you can't store any session data without first starting a session. Just read it, or your code wont work =)
  5. If I understand you correct, I would do the following: Lets say pages are page1.php, page2.php and page3.php, and I guess you want to have the form on page 3 to send all the information entered since page 1. If we have one text field on each page, and the first is for your given name, second for your surname and third for your age, it could look like this: page1.php: ... <form action="page2.php" method="post"> <fieldset> <legend>Personal information</legend> <label for="givenname">Given name:</label> <input id="givenname" name="givenname" type="text" /> </fieldset> <input type="submit" value="Go to page 2" /> </form> ... page2.php: ... <form action="page3.php" method="post"> <fieldset> <legend>Personal information</legend> <label for="surname">Surname:</label> <input id="surname" name="surname" type="text" /> <input type="hidden" name="givenname" value="<?php echo $_POST['givenname']; ?>" /> </fieldset> <input type="submit" value="Go to page 3" /> </form> ... page3.php: ... <form action="lastpage.php" method="post"> <fieldset> <legend>Personal information</legend> <label for="age">Age:</label> <input id="age" name="age" type="text" /> <input type="hidden" name="givenname" value="<?php echo $_POST['givenname']; ?>" /> <input type="hidden" name="surname" value="<?php echo $_POST['surname']; ?>" /> </fieldset> <input type="submit" value="Send my information" /> </form> ... lastpage.php would be the page you eventually send all the information to. Good luck
  6. I see your problem is 'solved', but I have to suggest you to use Apache's mod_rewrite, IF your server is an Apache of course. When I code my sites I normally have my index.php serving all pages (like you), i.e. index.php?page=blog etc. I then use mod_rewrite to 'hide' the file name and query string, thus having URLs like http://example.com/blog/. That's one of your problems solved. Read this article to get started with rewriting URLs: http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html. Like people are suggesting, you should verify your query strings, only allowing the pages that actually outputs stuff. I use a simple array of allowed pages, and then check if the query string in question is part of that array, like this: <?php $page_array = array("blog", "and", "the", "rest", "of", "pages"); if (in_array($_GET['page'], $page_array)) { $page_exists = "TRUE"; } else { $page_exists = "FALSE"; } ?> And then I output my 404 error message if $page_exists = "FALSE". You could also send users to another page if the query string is not in the array of allowed pages, and make sure that php stops executing code, like this: <?php $page_array = array("blog", "and", "the", "rest", "of", "pages"); if (!in_array($_GET['page'], $page_array)) { header("Location: URLTOPAGE"); exit; } ?> Remember that headers have to be sent before anything else, so this code snippet needs to be in the very top of your index.php. Hope I could help, or at least give you some ideas!
  7. Ahhh, found the answer myself. It's because Apache can't go back and do a 404 after it served the actual script (index.php) successfully. And I also found a workaround here: http://www.webmasterworld.com/forum88/12822.htm.
  8. No, you should only use the single URL you like the best (the first, right?). Don't make up different URLs for one page, it just doesn't make sense. The article you read is more about redirecting from http://www.* to http://* as an example (thus getting rid of the unnecessary "www." when people type it). You can get technical details for that specific rewrite here: http://no-www.org/
  9. It's always a good idea to have only one URL for one page, i.e. canonical URLs. Why have three? When a page is reachable from several URLs, (some) search engines will index them all, thus splitting the hits on each URL. Having one page with 1000 hits is better than having three identical pages with 1/3 of the hits.
  10. I'm coding a website driven by one main document (index.php) outputting different include-files via different query strings. I have two levels of pages, each page outputted via a query string (e.g. main pages "blog", "map" and "about" and sub pages "blog_tag", "map_country" and "about_me"). I then use Apache's mod_rewrite to rewrite the ugly URLs (e.g. "index.php?page=blog" rewritten to /blog/ and "index.php?page=blog_tag" rewritten to /blog/tag/) thus making it easier and prettier to distinguish between main and sub pages. Below is my .htaccess file (note that ALL URLs of the right type will be redirected to index.php?page=*, not only my 6 page names from above): RewriteEngine on RewriteBase / RewriteRule ^$ index.php?page=blog RewriteRule ^([a-z0-9]+)$ $1/ [R] RewriteRule ^([a-z0-9]+)/$ index.php?page=$1 RewriteRule ^([a-z0-9]+)/([a-z0-9]+)$ $1/$2/ [R] RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/$ index.php?page=$1_$2 ErrorDocument 404 /index.php?page=status_404 All that is working like a charm, but then I wanted a good "404 page not found" system. If someone browse the non-existent pages (i.e. query strings of the form * and *_*) "/blog/tga/", "/blo/", "/something/else/" or whatever, they should be sent to a "404 error page". Apache's "ErrorDocument 404" won't catch these kind of wrong pages, because every query string belongs to the file index.php, which IS existent. What Apache's ErrorDocument 404 will catch, is URLs like "/blog/tag/archive/" or "/jdklasjk-ds", but these are less likely to be typed I reckon. I tested it, and the ErrorDocument part is working like it should. In order to catch these wrong query strings, I have the following PHP code at the very beginning of my index.php file: <?php $page_array = array("status_404", "blog", "blog_tag", "map", "map_country", "about", "about_me"); if (!in_array($_GET['page'], $page_array)) { header("HTTP/1.0 404 Not Found"); exit; } ?> And this should be working fine I think, but for some reason, when I type something my filter should catch, like "/blogg/" the page turns out blank. I know that the if-statement is actually being processed (through testing), and the reason the page turns out blank, is because exit; is reached. My problem is, that the header seams to be ignored. The weird thing is, if I change the header to a "header("Location: /status_404");" the header is NOT ignored, and you're redirected to my error page "/status_404". Some may be fine with this 'solution', but I'd like it to work like it should. This way I will have two kind of 404 errors; one where it's served through my .htaccess file (that's the right way - the error page is showed still having the wrong URL you typed in the address bar of the browser) and the other where you are redirected to /status_404 (this way you can't check the URL you just typed for misspellings or the like). Get my point? Hope someone can help me out here with this annoying problem. BTW I've tested the above on both my localhost (PHP 4.4.7/Apache 2.2.4 win32) and web hotel (PHP 4.4.7/Apache 1.3.37 unix), with same results.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.