Squidge 101 Newbie Poster

Evening all

I am working my way through Zend Framework 1.x, and seem to have an issue.

I am trying to set the doctype() to HTML5:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function __initDoctype() {
        $this->bootstrap('view');
        $view = $this->getResources('view');
        $view->doctype('HTML5');
    }

}

I have check the documentation and using doctype('HTML5') seems to be correct, but my output keeps showing others.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Squidge 101 Newbie Poster

Any errors?

Squidge 101 Newbie Poster

+1 to pritaeas.

A simple google search will bring up some introduction tutorials which are nice to follow.
You will need:

a development environment locally (XAMPP/EasyPHP)
an IDE (NetBeans, Dreamweaver, even NotePad++), many chocies for these, so try a few, and see which one you are more comfortable with.

Squidge 101 Newbie Poster

try adding under line 8:

$sql->free();

Because you are not flushing the content

or use

unset($sql);
Squidge 101 Newbie Poster

Wheres the auto indent?

Ive started using netbeans, that would be handy :-)

Squidge 101 Newbie Poster

no one is going to go through 290+ lines of code for you.

Narrow it down

Squidge 101 Newbie Poster

Evening tuyendoan. In your .htaccess file you will need something like :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

This will remove the .php from the URL on the first level. You would need to test further for the deeper nested ones

Although i would suggest you look at why this anomoly is happening

Squidge 101 Newbie Poster

DO NOT USE THE MYSQL extension.

Although a lot of tuts will still use this, it has been superceeded by MySQLi.

You could also opt for, and one i use, PDO.

MySQLi basic connection:

$mysqli = new mysqli("localhost", "your_user", "your_password", "your_database");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
else {
..do something wonderful..
}

PDO & MySQL connection:

try 
{
    $dbh = new PDO('mysql:host=localhost;dbname=DATABASE_NAME', 'your_user', 'your_password');
} 
catch (PDOException $e) 
{
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
Squidge 101 Newbie Poster

Hi, i'm creating a image gallery, using .htaccess. And this is my first time i work with .htaccess

Simple, you cannot use .htaccess for this. You cannot execute code in that manner.

Squidge 101 Newbie Poster

this code snippet is written with dirty values? why write code for semeone and allow dirty values in one of the most vulnerable of php functions?
sanitize the post values or suffer the consequences.

this code snippet is written with dirty values? why write code for semeone and allow dirty values in one of the most vulnerable of php functions?
sanitize the post values or suffer the consequences.

This is very true.

Although the majority of code snippets you will get will require you to add code sanitizing.

Squidge 101 Newbie Poster

This is not actually a PHP question, but............

if you install the speed test extension for Chrome or Firefox, this will indicate where you can improve page speed.

Squidge 101 Newbie Poster

This is answered in one of CMSmadesimple FAQ section.

Squidge 101 Newbie Poster

I agree. People are not going to review 1000 lines. Post the code you pinned as the problem

Squidge 101 Newbie Poster

I would suggest in that case your install is incorrect

Squidge 101 Newbie Poster

Also page refresh the browser using ctrl + f5

Squidge 101 Newbie Poster

Have you tried just the php snippet:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Squidge 101 Newbie Poster

8m month old thread really????

Squidge 101 Newbie Poster

ok, how about:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.(php|html?)
RewriteRule ^(.*)$ $1.(php|html?)
Squidge 101 Newbie Poster

have you removed the '.php' from page links?

Squidge 101 Newbie Poster

@rch1231

Many thanks.

Squidge 101 Newbie Poster

Try:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME}\.php
RewriteRule ^(.*)$ $1.php
Squidge 101 Newbie Poster

@rch1231,

Blimey is it that old!?!?!?!?

It sound like it is that, although cannot find anything on the web about it

Squidge 101 Newbie Poster

Sorry, that would be a database engine

Squidge 101 Newbie Poster

Strange question i am afraid, i have a friend who is after information on a database called "Profile".

Does anyone have any links to this, as I have been unable to find anything

Squidge 101 Newbie Poster

I suspect you are not validating and cleansing your form input, and this has left it open to SQLInjection

Squidge 101 Newbie Poster

I use the same DB table for both admin and users.
They are identified by an additional column, for example:

:access: 0 = GOD, 1 = admin, 2 = user

So when you query the DB you need to validate the user, and also check against the access level that has been granted. You can then show additional content depending on access

Squidge 101 Newbie Poster

This is defined in your other post

Squidge 101 Newbie Poster

$script_url=$_SERVER['PHP_SELF']; //Change this if you want to use this as an include file.
$files_path="./album/"; // Where does the album start? Anything under the directory the script will read. With Trailing slash
$full_server="http://localhost:8080/phAlbum/album"; //Enter the full server path to where the albums start. //With Trailing Slash

I would say it is the same question as LastMitch has pointed out.

Anyway:

$script_url=$_SERVER['PHP_SELF']; //Change this if you want to use this as an include file.

This will telll you all about $_SERVER : http://php.net/manual/en/reserved.variables.server.php

$files_path="./album/"; // Where does the album start? Anything under the directory the script will read. With Trailing slash

As the comment on the script states: - This is where the gallery starts from

$full_server="http://localhost:8080/phAlbum/album"; //Enter the full server path to where the albums start. //With Trailing Slash

This is the test bed:

localhost = Local test URL (XAMPP etc)
phAlbum = The folder under htdocs where the script has been put
album = folder under /htdocs/phAlbum/ (see album path)

Looking at the README.TXT:

INSTALL INSTRUCTIONS

  1. Create an empty directory
  2. Set permissions on directory to 777
  3. Place 'gallery.php' in the directory
  4. Navigate to http://www.yoursite.com/yourdir/gallery.php
  5. The default password is 'admin' (Please change this by opening 'gallery.php' and changing the value of $password)

You need to create the folder album and chmod.

LastMitch commented: Nice Explanation! +10
Squidge 101 Newbie Poster

@diafol

Many thanks.

So from the link i have opted for, what i am asuming, the easier option:

file will be called autoLoader.php and added to the .ini include PATH to load in.

<?php
// autoload functions only
// loaded in order

#!! IMPORTANT !! -> Database connection load
function autoloadDataBase($className){
    $filename = 'classLib/dataBase/' . $className . '.php';

    if(is_readable($filename)){
        include $filename;
    }
}

function autoloadCRUD($className){

    $filename = "classLib/CRUD/" . $className .'.php';

    if(is_readable($filename)){
        include $filename;
    }

}

function autoloadRSS($className){

    $filename = "classLib/RSS/" . $className .'.php';

    if(is_readable($filename)){
        include $filename;
    }

}

spl_autoload_register("autoloadDataBase");
spl_autoload_register("autoloadCRUD");
spl_autoload_register("autoloadRSS");

?>

I am guessing there are many ways to tidy this up, if anyone can suggest i am open to suggestions :)

Squidge 101 Newbie Poster

ok, noted the above is probably a bad post, so to extend:

I have gone trhough many samples from goolge, one i have come across is the following:

spl_autoload_register(function ($className) {

    # Usually I would just concatenate directly to $file variable below
    # this is just for easy viewing
        $ds = DIRECTORY_SEPARATOR;
        $dir = __DIR__;

    // replace namespace separator with directory separator (prolly not required)
        $className = strtr($className, '\\', $ds);

    // get full name of file containing the required class
        $file = "{$dir}{$ds}{$classname}.php";

    // get file if it is readable
        if (is_readable($file))
            require_once $file;
});

Which seems fine - if you are calling the files from the same, or below folder structure.

My folder structure mimicks that of my namespace structure as per PSR-0

So my question:

How can this be adopted to be used globally?

Squidge 101 Newbie Poster

Hi all.

Does anyone have a good autoloader script for namespace classes ?

Namespace is identical to the file structure.

Squidge 101 Newbie Poster

@LastMitch
Many thanks, alas the link is for IT infrastructure Namespacing.

I shall keep digging and report back

Squidge 101 Newbie Poster

oh and remove global $db;

Squidge 101 Newbie Poster

Hi LastMitch,

Think it is bad practice to have the DB call in the class file.

From db.php remove 15 & 16.

Call this from with in function.php

<?php
include("db.php");
function PM() {

        $db = new foo_mysqli('xx','xxx','xxxx','xxxxx');

        $sql = "SELECT * FROM posts";
        $result = $db->query($sql) or die("It's not connecting");
        while($row = $result->fetch_assoc($sql)) {
        echo $row['Content'];

        $db->close();

    }
}
?>

Not sure if that helps. Half asleep now :)

edit: http://devzone.zend.com/255/using-ext-mysqli-part-ii_extending-mysqli/

Squidge 101 Newbie Poster

Hi all.

I recently set up dual boot Os (7, and Ubuntu 12.10).

The namespace call was/is working on the Windows 7 env (same version of XAMPP).

I know Linux is case sensitive so i have amended the file/folder calls.

Although the file exists, i am getting:

Message: Class classLib\dataBase\database_Connection could not be loaded

DB Class:

<?php
// root -> /classLib/dataBase/database_Connection.php:

namespace classLib\dataBase; // declare namespcae

class database_Connection {
/**
* @var PDO The database link.
*/

    protected static $dbLink;

    /**
    * Returns an open PDO object. This object will be shared
    * among all who call this method, so that you don't have
    * to be creating multiple connections to MySQL in the
    * same request.
    * @return PDO
    */

    public static function get()
    {
        if(self::$dbLink == null)
        {
            $dns = 'mysql:host=localhost;dbname=rtbClass'; //dev db
            self::$dbLink = new \PDO($dns, 'root', ''); //dev usage only as root
            self::$dbLink->exec("SET NAMES 'utf8'");
            self::$dbLink->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        }
        return self::$dbLink;
    }

    /*
    * We don't want this class to be able to spawn objects.
    * By making these two methods private, we effectively
    * prevent that from happening.
    */

    private function __construct() {
        return false;
    }

    private function __clone() {
        return self::get();
    }

}
?>

This is being called by a class that loads active Jquery/Java etc:

<?php
// root: -> /classLib/load/load_headScript.php :
spl_autoload_extensions(".php");
spl_autoload_register();

use classLib\dataBase\database_Connection as DB; // import namespace for code reuse

class load_headScript
{

    public function headLoad()
    {
        $sql = "SELECT scriptCode, scriptName FROM j_scripts WHERE active != '0'";
        $stmt = …
Squidge 101 Newbie Poster

I have lines changed 5 to 15 in above code, you can not write if in string formation.
remove all your 5 - 15 lines and only add following line.

$q = mysql_query("INSERT INTO kontakte (emri, mbiemri,e-mail,nr,adresa,shenime) VALUES('{$_POST['emri']}','{$_POST['mbiemri']}','{$_POST['email']}','{$_POST['nr']}','{$_POST['adresa']}','{$_POST['shenime']}')");

This is the same as what was in the original POST ^^

Squidge 101 Newbie Poster

From my understanding this is not going to work :

if(isset($_POST['emri'])){ $emri=$_POST['emri']}
 if(isset($_POST['mbiemri'])){ $emri=$_POST['mbiemri']}
 if(isset($_POST['email'])){ $emri=$_POST['email']}
 if(isset($_POST['nr'])){ $emri=$_POST['nr']}
 if(isset($_POST['adresa'])){ $emri=$_POST['adresa']}
 if(isset($_POST['shenime'])){ $emri=$_POST['shenime']}
 ) 

Your SQL is stating that "these fields" & "these values" you cannot use the if(isset... in this manner.

Try a dynamic SQL statement using:

$_POST as $field => $value

This takes the POST data and puts it into arrays, you would then step through them within you SQL stmt. So field and values are:

INSERT INTO kontakte ('$field[]') values ('$value[]');

*Note tested - this is an idea which you need to adapt

That way it will only use the POST fields that are isset.

*Side note - you should validate and clean any POST data

Squidge 101 Newbie Poster
Squidge 101 Newbie Poster

can you show a few lines before this line

if(isset($_POST['emri'])){
    $emri=$_POST['emri'];
}
Squidge 101 Newbie Poster

looking over a google search states HTACCESS cannot be used to alter global text in the manner you are trying to do

Squidge 101 Newbie Poster

As pritaeas has said:

remove the comma before FROM...

$query = "SELECT id, customer_name, address, postcode, telephone, mobile, mobiletwo, email, nservice
    FROM Customers WHERE DATEDIFF (CURDATE(), nservice) > 0";
Squidge 101 Newbie Poster

Thank you all for replying back, it is greatly appreciated. I have come across the code below, and would like to know your input:

class DB {

    private $dbh;
    private $stmt;

    public function __construct($user, $pass, $dbname) {
        $this->dbh = new PDO(
            "mysql:host=localhost;dbname=$dbname",
            $user,
            $pass,
            array( PDO::ATTR_PERSISTENT => true )
        );
    }

    public function query($query) {
        $this->stmt = $this->dbh->prepare($query);
        return $this;
    }

    public function bind($pos, $value, $type = null) {

        if( is_null($type) ) {
            switch( true ) {
                case is_int($value):
                    $type = PDO::PARAM_INT;
                    break;
                case is_bool($value):
                    $type = PDO::PARAM_BOOL;
                    break;
                case is_null($value):
                    $type = PDO::PARAM_NULL;
                    break;
                default:
                    $type = PDO::PARAM_STR;
            }
        }

        $this->stmt->bindValue($pos, $value, $type);
        return $this;
    }

    public function execute() {
        return $this->stmt->execute();
    }

    public function resultset() {
        $this->execute();
        return $this->stmt->fetchAll();
    }

    public function single() {
        $this->execute();
        return $this->stmt->fetch();
    }
}

The overall DB class i have in a namespace teh teh __construct would be removed/edited

Squidge 101 Newbie Poster

You are ending your message line and not actually including the returns:

$MESSAGE_BODY = "Name is contacting you from Mas Des Filles Contact Page" .""; 
 "------------------------------------------------------------\r\n" . 
    $MESSAGE_BODY = "Name: ".nl2br($_POST["contact_name"]).""; 
 "------------------------------------------------------------\r\n" . 
    $MESSAGE_BODY .= "Email: ".nl2br($_POST["contact_email"]).""; 
 "------------------------------------------------------------\r\n" . 
    $MESSAGE_BODY .= "Contact: ".nl2br($_POST["contact_tel"]).""; 
 "------------------------------------------------------------\r\n" . 
    $MESSAGE_BODY .= "Message: ".nl2br($_POST["contact_query"]).""; 
 "------------------------------------------------------------\n" . 
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY) or die ("Failure"); 

Try:

$MESSAGE_BODY = "Name is contacting you from Mas Des Filles Contact Page" ."\r\n"; 
 "------------------------------------------------------------\r\n" . 
    $MESSAGE_BODY = "Name: ".nl2br($_POST["contact_name"])."\r\n"; 
 "------------------------------------------------------------\r\n" . 
    $MESSAGE_BODY .= "Email: ".nl2br($_POST["contact_email"])."\r\n"; 
 "------------------------------------------------------------\r\n" . 
    $MESSAGE_BODY .= "Contact: ".nl2br($_POST["contact_tel"])."\r\n"; 
 "------------------------------------------------------------\r\n" . 
    $MESSAGE_BODY .= "Message: ".nl2br($_POST["contact_query"])."\r\n"; 
 "------------------------------------------------------------\n" . 
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY) or die ("Failure"); 
Squidge 101 Newbie Poster

Hi all,

I am putting together a CRUD. I have read through tutorials, and references.

Just wanted to see if i was on the right track:

<?php

// root -> /classLib/CRUD/CRUD

spl_autoload_extensions(".php");
spl_autoload_register();

use classLib\database\database_Connection as DB;

class CRUD {

private $id;   
#__construct to be extended  

public function __construct($id=null){

    $this->id     = $id;   
    #__construct to be extended   
}

public function save()
{
    try{
        $sql = "";
        $q = DB::get()->prepare($sql);
        $q->execute(array());
        }

    catch (Exception $e){
        print "Error: " . $e->getMeasage();
    }
}

public function update()
{

}

public function delete()
{
    try{

        $sql = "DELETE FROM [table to be clarified] WHERE id=:id";
        $q = DB::get()->prepare($sql);
        $q->bindValue(':id', $this->id, PDO::PARAM_INT);
        $q->execute();
    } 
    catch (Exception $e){
        print "Error!: " . $e->getMessage();
    }
}
// End of class
}
?>
Squidge 101 Newbie Poster

The faq-records.php file (form shortened for ease of reading - this all works fine on page load):

<?php
    $faqs = $objFAQ->get_admin_faqs();
    foreach ($faqs as $faq) {
?>

Looks like you are calling a class function, but have not included nor declared.

I am still very new to OOP. You have declared $objFAQ = new Faqs; in the main page code, this, as far as i understand, will not carry over unless as Diafol suggested, using sessions.

Hope it helps

Squidge 101 Newbie Poster

Drupal documentation is very well presented. Have u looked through it?

And as LastMitch said +1

Their forum is probably the best place to ask,

Squidge 101 Newbie Poster

Evening all.

I am using nivoSlider, and have come across an issue with ow i'd like it to work.

Here is a sample of the slider:

http://gavdev.roundthebend.info/index2.html

This is what i would like it to do:

http://www.directenergypurchasing.com/

This is the HTML:

<link rel="stylesheet" href="nivo-slider/nivo-slider.css" type="text/css" media="screen" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="nivo-slider/jquery.nivo.slider.pack.js" type="text/javascript"></script>

<script>
.nivoSlider {
    position:relative;
    background:url(images/loading.gif) no-repeat 50% 50%;
}
.nivoSlider img {
    position:absolute;
    top:0px;
    left:0px;
    display:none;
}
.nivoSlider a {
    border:0;
    display:block;
}

.nivo-caption {
    position:absolute;
    left:0px;
    bottom:0px;
    background:#B4B905;
    color:#005866;
    width:350px;
    height: 100%;
    z-index:8;
    padding: 5px 10px;
    padding-left: 35px;
    overflow: hidden;
    display: none;
}
.nivo-caption p {
    padding:5px;
    margin:0;
}
.nivo-caption a {
    display:inline !important;
}
.nivo-html-caption {
    display:none;
}

</script>
<div class="slider-wrapper">
    <div id="slider" class="nivoSlider">
        <img src="images/strategy-img.png" alt="" title="htmlcaption"/>
        <img src="images/sunrise.png" alt="" title="htmlcaption2"/>
            <img src="images/wind_header.png" alt="" title="htmlcaption3"/>
            <img src="images/solar_header.png" alt="" title="htmlcaption4"/>
            <img src="images/hydro_header.png" alt="" title="htmlcaption5"/>
    </div>
</div>

This is the JScript

<script type="text/javascript">
    // See http://nivo.dev7studios.com/support/jquery-plugin-usage/
        $(window).load(function() {
            $('#slider').nivoSlider({
                directionNav: false, // Next & Prev navigation
                controlNav: false, // 1,2,3... navigation
                controlNavThumbs: false, // Use thumbnails for Control Nav
                pauseOnHover: false, // Stop animation while hovering
                manualAdvance: false, // Force manual transitions
                effect: 'slideInRight', // Specify sets like: 'fold,fade,sliceDown'
                animSpeed: 450, // Slide transition speed
                pauseTime: 7000, // How long each slide will show
            });
        });
</script>  

What i would like it to do is have the text slide with the image. Can anyone assist?

JScript/JQuery are not my strong point at all, i know very very …

Squidge 101 Newbie Poster

Can you advise what u did so it can be searched for other users?

Squidge 101 Newbie Poster

www.google.com

Squidge 101 Newbie Poster

@LastMitch,

Think line 7 is wrong way round

echo "<img src='IMAGE/ITEMS/$image_folder_name/{$img['file']}' /><br>\n";
LastMitch commented: You are right. My bad. +7