Jump to content

yonta

Members
  • Posts

    70
  • Joined

  • Last visited

    Never

Posts posted by yonta

  1. I re-worked the directories and it no longer gives me that error.
    I had
    Classes ->
    Lite.php
    Cache ->
    File.php
    And i now have
    Classes ->
     Cache ->
     Lite.php
     Lite ->
      File.php

    But my script is still weird.
    After a remove of the cache, the next time it calls get, it will simply output a blank page instead of regenerating the cache. I have to hit Refresh to view the built page.

    So what happens is this: i view the page with the list of banners, next i delete a banner ($_GET request from link), it deletes the banner and shows an empty page, i hit refresh button in browser, and view the banner's list with the message that the banner has been deleted. Again, if i remove the cache everyting's fine.

    Why? Any clues?

    update: here's the delete function

    [code]
    function banners_Delete($ban_id)
    {
    $this->_start();
    CACHING == true? $this->objCache->remove('ban_list','banners'):'';
    $result = $this->banners->banners_GetOne($ban_id);
    $image_name = $result['ban_photo'];
    if(!$result || $image_name=='')
    {
    $_SESSION['feedback'] = 'Banner escolhido não existe.';
    $this->banners_List();
    return false;
    exit();
    }
    @unlink(SPATH_TO_BANNERS_IMAGES.$image_name);
    unset($result);
    $result = $this->banners->banners_Delete($ban_id);
    if($result === false)
    {
    $_SESSION['feedback'] = 'Erro ao eliminar banner escolhido.';
    $this->banners_List();
    return false;
    exit();
    }
    $_SESSION['feedback'] = 'Banner eliminado com sucesso!';
    $this->banners_List();

    }
    [/code]
  2. Hi :)

    I simply can't solve this. i'm trying to use pear's Cache_lite for the first time but it is unable to correctly remove cache files and detect if the cache file is good. I mean 'correctly' remove because it does empty the file but doesn't remove it and when a new call to cache->get is made, it just shows an empty page.

    When a call to remove or clean is made, it echos 'unable to remove cache file'. I've even tried setting the permission to 777 on the cache directory but to no avail.

    Of course, if i turn off caching everything works.

    My php version is 4. Please please help

    Here's my script (part of the whole controller script):

    [code]
    function banners_Controller()//contructor
    {
    $this->objCache = new Cache_Lite(array('cacheDir' => 'cache/',
    'lifeTime' => 3600,
    'automaticCleaningFactor '=>100,
    'pearErrorMode' => CACHE_LITE_ERROR_DIE));
    }
    function banners_List()
    {
    if (CACHING === true && $data = $this->objCache->get('ban_list','banners', false))
    {
    echo($data);
    } else {

    $this->_start();//include some scripts & set some variables
    require 'Savant2.php';
    $this->tpl = new Savant2(array('template_path' => 'templates'));


    $list = $this->banners->banners_GetAll();
    $list === false ? trigger_error("Erro ao aceder à lista de banners.", E_USER_ERROR): '' ;

    $this->tpl->assign('banners', $list);
    $this->tpl->assign('path', LPATH_TO_BANNERS_IMAGES);
    CACHING == true? $data = $this->tpl->fetch('banners_list.tpl.php'): $data =$this->tpl->display('banners_list.tpl.php');
    CACHING == true? $this->objCache->save($data, 'ban_list'):'';
    return true;
    exit();
    }
    function banners_Insert($ban_photo, $ban_ispub)
    {
    if(empty($ban_photo) || $ban_ispub=='')
    {
    $_SESSION['feedback'] = 'Não se esqueça de seleccionar a imagem.';
    $this->banners_List();
    return false;
    }
    $this->_start();
    require 'fileupload.class.php';

    //clear cache
    CACHING == true? $this->objCache->remove('ban_list','banners'):'';
    CACHING == true? $this->objCache->clean():'';


    //upload
    $upload = new FileUpload($ban_photo, SPATH_TO_BANNERS_IMAGES, 'jpg');
    $new_name = $upload->rename_filename();
    $result = $upload->upload($new_name);
    if($result[0]=== false)
    {
    $_SESSION['feedback'] = $result[1];
    $this->banners_List();
    return false;
    }


    //insert into db
    $db_insert = $this->banners->banners_Insert('ban_'.$new_name, $ban_ispub);
    if($db_insert === false)
    {
    $_SESSION['feedback'] = 'Erro ao guardar novo banner.';
    $this->banners_List();
    return false;
    }
    $_SESSION['feedback'] = 'Banner inserido com sucesso!';
    $this->banners_List();
    }
    [/code]

    Thanks for [b]any [/b]help
  3. That has to do with object-oriented coding. An object is mainly a name for an instance of a class.

    In this case, $CFG is an object that has a property ('wwwroot'), and this property is being set to 'http://site.local' .

    Somewhere in your script(s) there's probably a '$CFG = new NameofClass();' line. Find it and then check the class.

    For a better understanding, google php oop tutorial and read some or check here [url=http://www.phpfreaks.com/tutorials/48/0.php]http://www.phpfreaks.com/tutorials/48/0.php [/url]
  4. Hmm
    You could use $_REQUEST instead of get or post, since it checks both, although then you wouldn't know where the id was coming from which might pose some security issues.

    Well, i might do it like this (disposing of the ValidateNumric since it's only a wrapper for an existing php function)

    [code]
    if(isset($_POST)){
      if(!is_numeric($_POST['id]) ){
          echo 'bad..';
          exit(); }
    }elseif(isset($_GET)){
      if(!is_numeric($_GET['id]) ){
          echo 'bad'; //or generic display function for errors
          exit(); }
    }
    [/code]

    Basically if a post request was made, it will check the $_POST['id'] and likewise for get requests.

    'Also whats the advantage to adding: ? return true: return false; to the function?'

    That's simply the ternary operator, a shorter version of if. Basically it goes like this: condition ? (condition is met) : (condition is not met). Basically none, just a preference - it makes the code clearer for me. Of course, when i was doing this i realised that your function is the same as the is_numeric function, it either returns true or false like the native php function. So there seemed to be no need for it (with or without the ternary operator - it's the same).

  5. Don't know if this helps since i'm not that knowledgeable but i use this class - <a href="http://www.phpclasses.org/browse/package/2794.html">Secure Session</a>. Here's the description:

    "This class can be used to prevent security attacks known as session hijacking and session fixation.

    When a session is initialized the class computes a fingerprint string that takes in account the browser user agent string, the user agent IP address or part of it and a secret word. If the fingerprint value changes, it is very likely that the session was hijacked and it should no longer be accepted.

    To prevent session fixation attacks the calls the PHP session_regenerate_id() function so the session identifier changes everytime the session is checked."
  6. Not really sure about what you're asking but how about this

    [code]
    function ValidateNumric($value) {

    is_numeric($value)? return true: return false;

    }
    [/code]
    Then just use like this (put at the top of the page for example):
    [code]
    if(isset($_GET['id']) ){
    if(ValidateNumric($value) ){
                    //do stuff
            }else{
                  echo 'bad bad..';
            }
    }
    [/code]
  7. It would help if you tell what it does output as it stands. But here are some suggestions.

    Normaly when getting values from a mysql query i do this

    $file =$row['id']."-".basename($row['path']); - notice the '' around column names. i'm not sure if they are mandatory but that's the commom way.

    Then here i would o this:

    echo '<a href="javascript:na_open_window(\''.$name.'\',
    "ploggerb2.1/images/'.$row['path'].'", 0, 0, 0, 0, 0, 0, 0, 0, 0)"
    target="_self"><img src="ploggerb2.1/thumbs/'.$file.'" border="0"></a>';

    Using ' instead of " is quicker because php doesn't execute strings inside single quotes - this also means that when you want to print a variable you have to break the string and use the concatenation operator (.). Also when you want to escape quotes (be it single or double) use the backslash \ (notice the \ before the single quotes in $name variable).

    See more at [url=http://www.php.net/manual/en/language.types.string.php]http://www.php.net/manual/en/language.types.string.php[/url] on handling strings.

    Hope this helps  :)

  8. Hi:)

    i would like to build something like this : <a href="http://tryruby.hobix.com">try ruby in your browser</a> but using php (the language to learn) and flash (the interface). Basically a try php in your browser. The idea is to learn a bit more flash and php. It's all almost done but the problem is how do i stop the user from  writing code that exposes for example my site's password, or deleting all files, etc..

    I would like to allow only stuff like echo, print, array but not stuff like fopen, fwrite, unlink and a whole bunch of other functions or global variables. I would still like that users could make up their own variables names, instead of strictly following a tutorial i would write - this would allow me to predict everything that could be written and so i could validate the code string first before using eval on it, but this is not how the the try ruby works. You can input any word as a variable.

    I'm thinking that this is not actually possible but maybe someone knows of a solution?

    Thanks for any help
  9. Don't know if there's a simpler solution (hope there is) but you could do this:

    $path = 'http://www.mysite.com/example/index.php';
    print substr(strrchr(dirname($path), '/'), 1); //will return example

    If you want to just get the current directory (and not parse a url string), use <a href="http://pt.php.net/getcwd">getcwd</a> .

    best
  10. Here's an example (actionscript function):

    function loadwhatever(){
    var objSend:LoadVars = new LoadVars();

    /*Values to be sent (id) */
    objSend.id = '1';

    /*Send variable to php and load the variables*/
    objSend.sendAndLoad(whatever.php+"?nocache=" + Math.random(), objSend, "POST");

    /*When the results are loaded into flash - add this*/
    objSend.onLoad = function(ok) {

    //do something here
    }
    }

    In my experience you should force flash to not cache the results. Otherwise when you're testing you won't see he changes you made to the code.

    On the php side everything seems fine.
  11. Don't know if this is what you mean but it could be this.

    You would need a table, say called pages, with an id, title, text for example. If you would need to group pages into categories add a category_id field and a categories table to match.

    You could use tinymce for the editor to help the cms users edit the text in each page.

    Then to access an individual page you could do it like this www.domain.com/1/1/ which mapped to index.php?category=1&page=1 (by Apache's mod_rewrite) would then give you the page (just fetch the row from the database).

    Of course, if you would like to use the category name and page title, just use those instead of the id numbers. So, this
    www.domain.com/categoryname/pagetitle/
    would map to this
    index.php?category=categoryname&page=pagetitle

    You would then have to make sure that there isn't more than 1 page with the same title in each category.

    Just my quick thoughts. Hope it helps.

    Best,

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