Jump to content

gffg4574fghsDSGDGKJYM

Members
  • Posts

    195
  • Joined

  • Last visited

Posts posted by gffg4574fghsDSGDGKJYM

  1. ' is a xml/xhtml entities only, html doesn't have a entities for apos

     

    If you are using html you don't need to make a entity of the '/apos isn't needed at all no mater what charset you are using since aposthrophe is in the first 0-127 character(ASCII), if you are using xml you must (i think it's a must for xhtml too but i'm not sure as i don't know every detail of it).

     

    If you are using it in a URL you must encode it for both html and xhtml with rawurlencode()

    http://www.php.net/manual/en/function.rawurlencode.php

     

    What IE version are you using ? Did you use html or xhtml ?

  2. Example of code ? sure...download some frameworks that are made in php and look at the code.

     

    If you have hard time understanding MVC i don't think it's a good idea to create another frameworks yourself. The only exception that if you are very, very specific job to do and you aren't able to do it with all actual frameworks (which i very doubt) AND you think there enough people with the same need to create a framework for it instead of a custom software.

  3. 404 mean page not found, htaccess or not.

    If the htaccess was working on the localhost i assume some file are missing on the server.

     

    Did you copy profile.php and bebo-skin.php in the same directory with the htaccess ? did you try to access the page directly or with the htaccess mod_rewrite ?

  4. Model sand for data/database abstraction layer. Simply put you can create a php file mysql_model.php with a list of function that get/set data, all the SQL is handled in the model. Function like get_user_name() or set_user_name(). One day if you want to use Oracle instead of MySQL you only have to rewrite the mysql_model.php and make a oracle_model.php instead. No other change in the others part of the application will change. Only some data handling are autorised in this part like datatype cast or escape string.

     

    View is everything the user see and do, the graphical user interface. All the html/css and image. You can easly change it later to use xhtml instead of html or use XML, RSS feed or even a .exe to display the data. It shouldn't containt any actual code else that some foreach to display table (or some similar). You can make the controller save all the data into a array and call the view with it, the view put the data into a html code.

     

    Controller is everything else. It receive the data from the view part, process it, save it with the model, retrieve it with model and sent it to view to be displayed. You can make a index.php get the full URL, ask the model for the data you need for that page, process the data as needed and call the view  for that page with data.

     

    While it can be a good thing to build a MVC yourself to learn from it, it may not be a good idea to use it in a live production system. Many good frameworks exist for that. They have the MVC built-in.

  5. This should work :

     

    <?php
    
    $email = "tes.t@hotmail.Com";
    
    if (!eregi("^[a-z0-9\-\_\.\%\+]+@[a-z0-9\-\_]+\.[a-z]+$", $email))
    {
    echo "Invalid Email! ".$email;
    } else {
    echo "Valid Email! ".$email;
    }
    
    ?>

     

    However it won't work for email address using IP address instead of a domain name. It may return some false positive and probably need to be better tested before use.

  6. You want to force a download ?

     

    Use that :

    <?php
    $filename = "something.csv";
    $csv = "1,2,3,4
    2,3,4,5
    3,4,5,6";
    
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.$filename);
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . strlen($csv));    
    
    echo $csv;
    ?>

  7. I think you are looking for $_SERVER['REFERER'] instead of Request URI. But i'm not sure the referer work in a 404 or others error case, and the referer is unreliable because it's provided by the client.

     

    You may want to redirect anything that not a file to a php scripts instead to catch up 404. Like that :

    .htaccess

    Options +FollowSymLinks
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ log.php?request=$1 [NC,L]
    </IfModule>

     

    log.php

    <?php
    
    /* Tell the page doesn't exist */
    header("HTTP/1.0 404 Not Found");
    
    if (isset($_GET['request']))
    {
      /* Save it in database or somewhere */ 
    }
    
    ?>
    <html>
      ....
    </html>
    

     

    Or you may search for a software that read apache logs and display you only the 404 request.

  8. PHP have ftp tools you can use to download, resize the thumbnails (gd) and save them local. It always depend on how many images you have but i'm not sure you can do this without being kicked by the timeout or the user will close the window thinking your site doesn't work or the browser may display a timeout even if your script work and you increase the time limit.

     

    http://www.php.net/manual/en/book.ftp.php

    http://www.php.net/manual/en/ref.image.php

     

    You can also created a cron job that run each x hours and connect to the ftp, download the file, makes thumbnails and make a 'static' html file. Some sort of a html mirror of a ftp.

  9. Build your php like that php/mysql first then html :

     

    <?php
    
    require_once('database.php');
    ...
    $error = "User profile not found";
    
    /* if you found a error you can redirect the user
       because no html have been output yet */
    if (isset($error))
    {
      header("HTTP/1.0 404 Not Found");
      header('Location: http://www.mysite.com/404.html');
      die();
    }
    $is_admin = false;
    ...
    
    /* then display the html if needed */
    ?>
    <html>
    <body>
    <?php 
    if (isset($error)) echo '<div class="error">'.$error.'</div>';
    ?>
    ...
    <?php
    if ($is_admin) echo "Administration";
    ?>
    </body>
    </html>

     

    Instead of half html, then php/mysql, then the bottom half html:

     

    <html>
    <body>
    <?php
    require_once('database.php');
    ...
    /* now if you got a error you are stuck out of options
        you can't redirect because some data already been send
        and you can't die() because you will get half a page and no bottom*/
    ?>
    </body>
    </html>

     

    If you want to push this a little bit more you can put your entire website html in a single html/php file like this :

     

    display.php

    <?php
    if (!$call_from_php) die();  /* prevent call directly from browser*/
    ?><html>
    <head>
    <title><?php echo $title; ?></title>
    </head>
    <body>
    <?php
    if ($is_admin)
    {
    ?>
    <h1>Administator Section</h1>
    <?php
    }
    ?>
    <?php
    if ($is_user)
    {
    ?>
    <h1>Registered User Section</h1>
    <?php
    }
    ?>
    <h1>Public section for everyone</h1>
    </body>
    </html>

     

    and then in your main php file you 'call' the display like that :

    <?php
    /* database and stuff */
    
    /* Set value for display depend on what results you have from databse*/
    $call_from_php = true;
    $is_admin = false;
    $is_user = true;
    $username = 'joe';
    require('display.php');
    ?>

     

    So you don't have to mix database query, bussiness logic with html tag. If you got a error in html you know where to look all in the same file you don't have to search everywhere. You want to provide alternate content like for mobile phone, great only create a 'display_mobile.php' and call this file instead of 'display.php' when the user has the options 'mobile' in his profile. You don't have to rewrite the whole website, only the view part. It allow flexible error handling and it's easier to maintain.

     

    Maybe i put it a bit too far for your need, but you got the idea from separating html and php/mysql.

  10. Don't echo html before doing the php/mysql.

     

    Put all the php script and mysql query at the top of the page. You can still use http header to redirect the visitor to a 404 page or alternate content from what error you got. Store the data/error in variable and in array.

     

    Put all the html at the bottom with minimal php scripts inside (only what you need to display the data) like some echo and foreach to display list and table. With some if to display part of html and taking care of error display.

     

    May not be as good pratice as Object Oriented Programming with separate class for each model, view, controler. But separate HTML from php/mysql will prevent that kind of issue.

  11. I ran some test and it work for me with that :

     

    setcookie.php

    <?php
    
    setcookie("cookie1", "itwork");
    setcookie("cookie2", "yeah");
    
    ?>

     

    displaycookie.php

    <?php
    
    print_r($_COOKIE);
    
    ?>

     

    test.php

    <?php
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1/displaycookie.php");
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_COOKIE, "cookie1=".$_COOKIE['cookie1']."; "."cookie2=".$_COOKIE['cookie2']);
    $content = curl_exec($ch);
    curl_close($ch);
    echo "<pre>".$content."</pre>";
    
    ?>

  12. I didn't even know this was possible with file_get_contents. You may want to take a look at cUrl instead.

     

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/page.php?id=205");
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_COOKIE, "......");
    $content = curl_exec($ch);
    curl_close($ch);
    echo "<pre>".$content."</pre>";

     

  13. regarding q1 I take it I would need direct access to the appache config file?

    I'm not sure about your configuration but i think not, you should be able to put it in a .htaccess.

     

    For the others question you can use this :

    Options +FollowSymLinks
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule  .....some rules.......
    </IfModule>
    

    RewriteCond %{REQUEST_FILENAME} !-f will prevent the rewriterule to work if the file exist, like php, image, css, javascript and if not file exist with that name use the rewriterule.

     

  14. I don't think Latin1 (ISO8859-1) is faster than UTF-8.

     

    ISO8859-1 only use 1 byte per character. It can save space in database and strlen() will work fine. It can display most America, Western Europe and Africa language.

    You can see the characters list here :

    http://en.wikipedia.org/wiki/ISO_8859-1

     

    UTF-8 may use more than 1 byte if needed per characters (variable length). It may take a lot more space in database than latin1 if you use a lot of japanese/chinese. You can store almost any language in the same database. It may not work (if you use any special chars) with strlen unless you utf8decode() it or use mb_strlen().

     

    The first 127 characters of these charset are ASCII and are the same, so if you use htmlentities() or only use the 127 first characters you don't need any special function to convert from one charset to the others. If you don't use any special charaters they are the same (and you can't make the difference between them).

     

    If you are sure to never need more than America, Western Europe and Africa language (english, french, spanish, ...) go for ISO8859-1

    Anything else UTF-8.

     

    I don't know Croatian but from what i have read it didn't seem to fit in ISO8859-1. (Wikipedia)

     

    latin1 handles the standard ASCII character set... nothing more.

    I think you are wrong here it can handle 256 characters including most special characters you can see with latin language like french.

  15.  

    1st q: Change filetype? Is it possible to change the lets say index.php to index.whateveriwant

    Yes just add another type in .htaccess/apache config like that :

     

    AddHandler application/x-httpd-php .php

    You can use any extension you want and all file with that extension will be processed as if it was a php

     

    You can use FilesMatch too like this :

    <FilesMatch "\.(css|style)$">
    SetHandler application/x-httpd-php
    </FilesMatch>

    Will process file with .css and .style as php file.

     

    2nd q: i have the a my rewrite rule in the htdocs folder if a user sets www.iamdj.co.uk/djname it will do this www.iamdj.co.uk/dj/display/djname now I already have this working but what I want is if someone goes to www.iamdj.co.uk it displays the index.php file instead of transfering.

    What exactly are you trying to do ?

     

×
×
  • 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.