Jump to content

esbenp

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Everything posted by esbenp

  1. I have forced PHP to make my url's lowercase by doing $url = $_SERVER['REQUEST_URI']; $pattern = '/([A-Z]+)/'; if(preg_match($pattern, $url)) { $new_url = strtolower($url); Header( 'HTTP/1.1 301 Moved Permanently' ); Header( 'Location: ' . $new_url ); } which seems to work right if this is a bad way to do it, please tell me so i've also just found out what you ment by the last bit, so i don't need any explaination there either heh
  2. Very nice! This works very well for me, and i learned a few things too I had not thought about the [NC] on hostname, since it will always be lowercase heh I do have a couple of questions though: [*]Can i make the 2nd rule relative? My site is currently in http://localhost/site/, and when im doing http://localhost/site/controller/, it redirects to http://localhost/controller. I know i could just type in /site/$1, but it annoys me, that i have to do it manually like that [*]How do you force the lowercase in PHP? Testing the url with preg_match, and then making a 301 redirect with header() ?? [*]Why do you split the last part up, into so many chunks? [*]I'm not sure i understand the last part, with the $|/ instead of just $? i don't get any 404 by using site/controller/param/extra?param=1, when i'm using the one without but thanks alot for your help, now i can finally move on!
  3. You could validate the username using preg_match, something like. $username = $_GET['username']; if(preg_match('/^[a-zA-Z]+$/', $username)) { echo(json_encode(array('Response'=>1))); } else { echo(json_encode(array('Response'=>0))); } then it would be easy picking up the response using a library like jQuery, which has the $.getJSON function. <script type='text/javascript'> $(document).ready(function() { $('input[name=username]').bind('keyup', function() { $.getJSON('validation_file.php', {username: $(this).val()}, function(data) { var response = parseInt(data[0].Response); if(response === 1) { // valid } else { // not valid } }); }); }); </script> <input type='text' name='username'> first you attach the keyup event to your field, which means the following function fires whenever the user releases a keyboard key, with the field in focus. It then checks the validation file (which contains the php part) and sends the username along in a $_GET variable. The php script then validates it using reg ex an returns an response array encoded as json. Please note i have not tested this code and it is highly likely to have flaws in it
  4. Hello, i'm just about to become bald, because mod_rewrite is making me tear my hair out. Basicly like alot of people, i like sexy urls, mostly because of SEO... and offcourse. It's sexy So what i need from my rewrite is the following: It should 301 redirect all urls to http://www.domain.com, for instance: http://domain.com->http:///www.domain.com, www.domain.com->http://domain.com If the url ends with a trailing slash, then it should be removed to avoid duplicate content, for instance: /controller/params/->/controller/params, /controller/->/controller I would love if it could convert all url's to lowercase, but as far as i can tell you can only do that with RewriteMap, and you need access to apache conf for that, right?? Most important: it should convert urls like theese: controller/, controller/params/, controller/params/extraparam/ -> index.php?controller=$1, index.php?controller=$1&param=$2, inde.php?controller=$1&param=$2&extraparam=$3 So far i've got something like this: RewriteEngine on RewriteCond %{HTTP_HOST} ^domain\.com [NC] RewriteRule ([a-z0-9/-]*) http://www.domain.com/$1 [R=301,L] RewriteRule ([a-z0-9/-]*)/$ ${HTTP_HOST}/$1 [R=301,L] RewriteRule ^([a-z0-9]+)/?([a-z0-9]*)/?([a-z0-9]*)$ index.php?worker=$1&param=$2&extraparam=$3 [L] the last part seems to work, but if i end my url with a trailing slash like this: http://localhost/site/controller/ it redirects to http://localhost/C:/xampp/htdocs/site/${HTTP_HOST}/controller i havn't tested the first part yet, but does it seem very wrong to any of you?? And how do i make my trailing slash rule work?! Is it possible for me to convert to lowercase, without messing with the httpd.conf? And do any of you have any other comments regarding the url structure or the rewrite patterns in general?? Thank you so much for taking your time to read through this rabble, and thank you for any help in advance
  5. Hey, i'm am trying to change a project into UTf8 encoding, since i always have trouble with iso-8859-1. So far i've changed all my tables in the database to utf8_unicode_ci, and i've changed my meta tag to <meta http-equiv="content-type" content="text/html;charset=utf-8" /> I'm also using the SET NAMES utf8 command, right after making my db connection. Then i've opened all the files one by one in notebook and saved it as utf8 instead for ansi. I have then checked all the files, one by one, by opening them in the browser (chrome), and it said they all were utf8 (by using the find automatic encoding func). I'm using Netbeans and i've set my project encoding to utf8 aswell... When i opened the files in notepad and saved them again as utf8 they all got a small char (´ (i think)) at the very beginning at the file, which fucked up my sessions (headers already sent bla bla), and it is only visible in netbeans (cant see it in notepad nor chrome when i view source). So i've removed the char and saved the file and BAM, back to ISO-8859-1 for some fucked up reason i really hope someone knows Any suggestions!?
  6. nevermind, got it working with function csv_to_array($csv, $delimiter = ',', $enclosure = '"', $escape = '\\', $terminator = "\n") { $handle = fopen($csv, 'r'); if ($handle) { set_time_limit(0); //the top line is the field names $fields = fgetcsv($handle, 4096, ','); //loop through one row at a time $i = 0; while (($data = fgetcsv($handle)) !== FALSE) { $r[$i] = array_combine($fields, $data); $i++; } fclose($handle); } return $r; } :D:D
  7. It didn't output anything, i've got some other code here, which does the trick, it generates this array: array 'ARAGR' => string '200' (length=3) 'ARANR' => string '80' (length=2) 'Bezeichnung' => string '195/70 R 15' (length=11) 'Hersteller' => string 'FIRESTONE' (length=9) 'Profil' => string 'CVW3000' (length=7) 'Demo' => string '$' (length=1) 'Zusatzbezeichnung' => string '' (length=0) 'Tragfaehigkeit' => string '104/102' (length=7) 'verfLB' => string '128' (length=3) 'aktLB' => string '128' (length=3) 'VK8' => string '465.87' (length=6) 'Breite' => string '195' (length=3) 'ARSQU' => string '70' (length=2) 'ARSGI' => string 'R' (length=1) 'ARSZG' => string '15' (length=2) 'ARTID' => string '200' (length=3) 'ARRART' => string '8' (length=1) 'AREAN' => string '3286347597015' (length=13) 'ARHKE' => string '.00' (length=3) 'ARHANR' => string '75970' (length=5) 'ARGEW' => string '11' (length=2) function csv_to_array($csv, $delimiter = ',', $enclosure = '"', $escape = '\\', $terminator = "\n") { $handle = fopen($csv, 'r'); if ($handle) { set_time_limit(0); //the top line is the field names $fields = fgetcsv($handle, 4096, ','); //loop through one row at a time while (($data = fgetcsv($handle)) !== FALSE) { $r = array_combine($fields, $data); } fclose($handle); } return $r; } but it takes one row any ideas how to make it fill the array with the rest?
  8. Hey Guys, i have a project to deliver in like 3 hours, i found a function on php.net to parse a csv file into an array, and made my code after that. The problem is, this function uses str_getcsv(), which is only available in 5.3, but my clients stupid server is 5.2.10 (talking about bad luck ) function csv_to_array($csv, $delimiter = ',', $enclosure = '"', $escape = '\\', $terminator = "\n") { $r = array(); $rows = explode($terminator,trim($csv)); $names = array_shift($rows); $names = str_getcsv($names,$delimiter,$enclosure,$escape); $nc = count($names); foreach ($rows as $row) { if (trim($row)) { $values = str_getcsv($row,$delimiter,$enclosure,$escape); if (!$values) $values = array_fill(0,$nc,null); $r[] = array_combine($names,$values); } } return $r; } this is the function i used, can anybody please show me what to edit to make it functional in 5.2.10 ??? thx
  9. Hmm.. I'm having a hard time seeing any logic in that, but it sure helped, thanks :-)
  10. Hello, i have a wierd problem, or maybe i'm just too tired to se it for myself :-) $patterns = array( "firstname"=>"/^[A-Za-Z-æøå]{2,64} [A-Za-zæøå]?$/", "lastname"=>"/^[A-Za-zæøå-]{2,32}$/", "adress"=>"/^[A-Za-zæøå\.]{5,32} [0-9]{1,5} [A-Za-zæøå0-9\.]?$/", "city"=>"/^[A-Za-zæøå]{2,32}$/", "postnr"=>"/^[0-9]{4,4}$/", "tlf"=>"/^\+?[0-9]{8,10}$/", "email"=>"[A-Za-z0-9._]{2,32}@[A-Za-z0-9]{2,32}\.[A-Za-z]{2,5}" ); foreach($_POST as $key => $value) { if($key !== "shipping" || $key !== "payment" || $key !== "next_x" || $key !== "next_y") { if(preg_match($patterns[$key], $value)) { // do stuff.. } } } It keeps ignoring my || operators, and checks the "trash" of my $_POST array? Does anyone see why? And please comment on my patterns, if you'd like :-)
  11. yeah what i meant was how, but nevermind i found out that if i use MYSQLI_ASSOC (as i prefer), you cannot use multiple columns with the same name. So i've used MYSQLI_NUM in this case and now it works like a charm :-) thanks alot for all your help
  12. ah great got it working! :-) thx alot! now the next problem, i couldn't find any info regarding how to use this sql sentence? id manufactor tiretype dimensions speedindex price stock id name id name id name 1 1 1 1 1 525.25 5 1 Bridg... 1 H: asldksaj... 1 Sommerdæk so how do i select the names of each table? like $result["m.name"], $result["s.name"] ???
  13. Okay, so manufactors, tiretypes and speedindex id's need to be foreign keys, to connect to the primary key in the products table? And then when i've done that, what should my sql query look like?
  14. PRODUCTS TABLE ---------------------- id - Id of the product manufactor - The manufactor speedindex - - tiretype - - Example: ID: 1 Manufactor: 1 Speedindex: 2 Tiretype: 2 -------------------------- MANUFACTORS TABLE -------------------------- id name - name of the manufactor -------------------------- SPEEDINDEXES TABLE -------------------------- id name - name of the speedindex -------------------------- TIRETYPES TABLE -------------------------- id name - name of the tiretype ------------------------ Thats my tables, now i searched the products table for a product with theese values (manufactor=1,speedindex=2,tiretype=2) and i need to show the name of theese 3 id's. I could do this if i did multiple queries, but i would like to do it in 1. Was that a bit easier? :-)
  15. Hi Forum! I'm doing a webpage for a client. It's basicly a webshop selling car tires. Now i have a table in my db, called products (manufactor, tiretype, speedindex) Each field contain a id which refers to 3 other tables (manufactors, tiretypes, speedindexes). Each of theese tables only got a id and a name, now after i've done my search i need to pull out the names according to the id's from the first table. I'm pretty sure this should be done with JOIN, but im really clueless about join, so could any of you help me? :-)
×
×
  • 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.