cereal 1,524 Nearly a Senior Poster Featured Poster

If your computer is enough performant you can install Windows inside VMware: http://www.howtogeek.com/howto/18768/run-windows-in-ubuntu-with-vmware-player/

siaswar commented: I know that and that works. no Vbox +0
cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, you can also add trim() to $name1: ${"name" . $i} = trim($array[$z]); and you can do the same with $val1.

cereal 1,524 Nearly a Senior Poster Featured Poster

It works for me, try to use var_dump on $name1: var_dump($name1); if Hello World is the first of the array, then the problem is this line ${"name" . $i} = $array[1]; because the array starts from 0, using $array[1] in my example $name1 will print How Are You?, so try to change it to ${"name" . $i} = $array[0];. If you are going to loop then just switch $i to 0.

This is what I've done, raw_data.txt example:

Hello World(.)How Are You?(.)Bless this mess!

script:

<?php
$filename = dirname(__FILE__) . "/raw_data.txt";

$fp = @fopen("$filename", 'a+');
if ($fp){
    $array = explode("(.)", fread($fp, filesize($filename)));
}

var_dump($array);
$i = 1;
${"name" . $i} = $array[0];
$val1 = "Hello World";

if ($name1 == $val1){
    echo 'yes' . "\n";
}
else{
    echo 'no' . "\n";
}
//second try
if ($name1 === $val1){
    echo 'yes' . "\n";
}
else{
    echo 'no' . "\n";
}

//3'rd attempt

if((string)$name1 === $val1){
    echo 'yes' . "\n";
}
else{
    echo 'no' . "\n";
}

var_dump($name1);

?>

will output:

array(3) {
  [0]=>
  string(11) "Hello World"
  [1]=>
  string(12) "How Are You?"
  [2]=>
  string(16) "Bless this mess!"
}
yes
yes
yes
string(11) "Hello World"
cereal 1,524 Nearly a Senior Poster Featured Poster

How the file is read? Can you paste that code? If you use file() function then you get an array of strings: http://php.net/manual/en/function.file.php

cereal 1,524 Nearly a Senior Poster Featured Poster

Change $array[1] = Hello World; to $array[1] = 'Hello World'; and then it will work, bye :)

cereal 1,524 Nearly a Senior Poster Featured Poster
cereal 1,524 Nearly a Senior Poster Featured Poster
cereal 1,524 Nearly a Senior Poster Featured Poster

Remove the () from the regex, seems to work for me:

<?php

function translate($content,$lang){
    $l = $lang;
    $pattern = array('en'=>'/\{\{.[^\}\}]*\|\|/','cy'=>'/\|\|.[^\{\{]*\}\}/'); # change this
    $brackets = array('en'=>'}}','cy'=>'{{');
    $content = preg_replace($pattern[$l],'',$content);
    $content = str_replace($brackets[$l],'',$content);
    return $content;
}

$content=<<<CONTENT
<p>{{Dyma destun (cy example) rand ||Here's some text en (example) rand}}</p>
CONTENT;

echo translate($content,'en');

echo "\n";

?>

or I'm missing the problem? o_o'

diafol commented: Spot on! Thanks again :) +14
cereal 1,524 Nearly a Senior Poster Featured Poster

This happens also in javascript, I found this problem while working on a cart application. Check also these: http://stackoverflow.com/questions/3726721/php-math-precision & http://stackoverflow.com/questions/1458633/elegant-workaround-for-javascript-floating-point-number-problem

broj1 commented: Good information, thnx +5
cereal 1,524 Nearly a Senior Poster Featured Poster

Perfect, just remember to use truncate outside the loop. I forgot to mention that in my example, but that was the main problem, bye!

(if we have finished mark the thread solved!)

cereal 1,524 Nearly a Senior Poster Featured Poster

Change your code from line 9 to 26 with this:

<?php

$file = file('file.txt'); # read file into array
$count = count($file);

if($count > 0) # file is not empty
{
    $milestone_query = "INSERT into milestones(ID, NAME, URL, EMAIL, LOGO, ADTEXT, CATEGORY, PUBDATE) values";
    $i = 1;
    foreach($file as $row)
    {
        $milestone = explode('|',$row);
        $milestone_query .= "('$milestone[0]',  '$milestone[1]', '$milestone[2]', '$milestone[3]', '$milestone[4]', '$milestone[5]', '$milestone[6]', '$milestone[7]')";
        $milestone_query .= $i < $count ? ',':'';
        $i++;
    }
    mysql_query($milestone_query) or die(mysql_error());
}
?>

If you echo the output of $milestone_query you will see something like this:

INSERT into milestones(ID, NAME, URL, EMAIL, LOGO, ADTEXT, CATEGORY, PUBDATE) values('ID1', 'NAME1', 'URL1', 'EMAIL1', 'LOGO1', 'ADTEXT1', 'ADTEXT1', 'CATEGORY1'),('ID2', 'NAME2', 'URL2', 'EMAIL2', 'LOGO2', 'ADTEXT2', 'ADTEXT2', 'CATEGORY2'),('ID3', 'NAME3', 'URL3', 'EMAIL3', 'LOGO3', 'ADTEXT3', 'ADTEXT3', 'CATEGORY3')

Besides, I count 9 keys in the array, not 8:

Array
(
    [0] => ID1
    [1] => NAME1
    [2] => URL1
    [3] => EMAIL1
    [4] => LOGO1
    [5] => ADTEXT1
    [6] => ADTEXT1
    [7] => CATEGORY1
    [8] => PUBDATE1

)

so pay attention to array keys 5 and 6 which in this example are the same and check if ID in your table is INT, in this case it will not accept a string like ID1, ID2 but only numbers.

cereal 1,524 Nearly a Senior Poster Featured Poster

You can browse the forum because only the script used to save the post is accessible to qualified users. When a user sends a post, then the script checks for the referer and redirects the user back to the original thread. In this case you will need $_SERVER['HTTP_REFERER'] or as in daniweb you will need an hidden input field which sends the link of the thread as value, this is used to redirect and to get category, subcategory, thread id...

In the case, for example on daniweb, you want to access directly to your edit_profile which is a restricted page, but the session ends or you logged out, you will need to save the $_SERVER['REQUEST_URI'] and redirect the user to the login page, from which then you go to the saved destination.

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

If you want a redirect then you have to restrict an entire page, not a block, you can append this script at the top of a page which is allowed only to logged users:

include 'dbconnection.php';
include 'functions.php';
if(login_check() === false)
{
    $_SESSION['destination'] = $_SERVER['REQUEST_URI'];
    header('Location: login.php');
}
else
{
    if(isset($_SESSION['destination']))
    {
        unset($_SESSION['destination']);
    }

    #
    # restricted page
    # include/echo or just redirect
    echo 'hello';

}

and change line 10/11 in your process_login.php of the posted script:

if(login($email, $password, $mysqli) === true)
{
    // Login success
    if(isset($_SESSION['destination']))
    {
        header('Location: '.$_SESSION['destination']);
    }
    else
    {
        include("XICS.php");
    }

}
else
{
    // Login failed
    header('Location: login.php?error=1');
}

Try this, but you can also see if someone of the users of the other thread will continue to help you here, they will certainly have a better picture of the project than me.

cereal 1,524 Nearly a Senior Poster Featured Poster

Let's simplify, in your code you have:

if(login_check($mysqli) == true)
{
    # restricted
}
else
{
    # public
}

so, login_check() performs a query to match user and password each time and for each restricted block in your pages? Is this function included inside dbconnection.php? If yes, do you store submitted username and password somewhere like $_SESSION or $_COOKIES?

In my example you have to use session_start(); on top of each restricted page and also inside the login page, and I'm assuming you use a $_SESSION to enable access into a restricted area, as example $_SESSION['logged']. But your approach seems to be different. How does your login script works, can you post that code? (remember to remove database username, password and hostname!)

cereal 1,524 Nearly a Senior Poster Featured Poster

In your restricted page enable a $_SESSION to record the $_SERVER['REQUEST_URI'], for example:

<?php
if(!isset($_SESSION['logged'])) # this is where you check if access is allowed
{
    $_SESSION['destination'] = $_SERVER['REQUEST_URI'];
    header('Location: login.php');
}
else
{
    if(isset($_SESSION['destination']))
    {
        unset($_SESSION['destination']);
    }
}
?>

And in you login script, after you validate the credentials replace your redirect with this:

if(isset($_SESSION['destination']))
{
    header('Location: '.$_SESSION['destination']);
}
else
{
    header('Location: default_restricted.php');
}

bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Check this project: http://code.google.com/p/red5-flex-streamer/
it's done with java, flash and php.

diafol commented: nice +0
karthik_ppts commented: Thanks for your valuable link +7
cereal 1,524 Nearly a Senior Poster Featured Poster

Usually you ca use $_SERVER['HTTP_REFERER']; but it seems that Gmail doesn't send the referer header: https://mail.google.com/mail/help/intl/en_GB/more.html#protecting

cereal 1,524 Nearly a Senior Poster Featured Poster

You can use a CSS rule:

<style type="text/css">
code span { color: #000 !important; };
</style>

or just change the highlight_string() function with htmlentities():

echo '<pre><code>';
echo htmlentities($string);
echo '</code></pre>';

bye! :)

cereal 1,524 Nearly a Senior Poster Featured Poster

In your code you have $q declared in line 19 and 22, the first query statement will be overwrited by the second and only this last will be performed by mysql_query.

At line 23 add or die(mysql_error()); to see if there is an error.

Also change $r.mysql_close(); with mysql_close(); or add as first argument the link identifier, not the query variable: http://php.net/manual/en/function.mysql-close.php

cereal 1,524 Nearly a Senior Poster Featured Poster

You can use highlight_string(): http://www.php.net/manual/en/function.highlight-string.php

<?php
$string = '
<?php 
    if($c==1)
    {
        echo $c;
    }
?>
';

echo highlight_string($string,true);
?>
cereal 1,524 Nearly a Senior Poster Featured Poster

Line 69:

 $image_random_name= random_name(15).".".$extension ;

try this:

 $image_random_name = $_FILES['image']['name'][$i];

or you can use $filename which is declared in line 58 and change line 70 to:

$copy = @move_uploaded_file($_FILES['image']['tmp_name'][$i], $images_location.$filename);

Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

In addition, an injection it's a string which can change the behaviour of the query, it's not related directly with XSS:

https://www.owasp.org/index.php/SQL_Injection
https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)

cereal 1,524 Nearly a Senior Poster Featured Poster

Check the length of the password field in the database, you wrote:

my password is = "y"
the one that i log in =d41d8cd98f00b204e9800998ecf8427e
the one in db = 415290769594460e2e48

now:

echo md5('y'); #outputs 415290769594460e2e485922904f345d

which is the same of the db version, but it seems that in your database the field is accepting only 20 chars, so change varchar(20) to varchar(32) which is the standard output for md5 function. And update the field with the new value, since the previous is truncated.

The hash that you get from the form, is generated by a boolean false:

md5(false); #outputs d41d8cd98f00b204e9800998ecf8427e

so check with a print_r($_POST); what you receive from the form. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Try this:

<?php

namespace Dbase;
class Dbconn
{
    public function conn()
    {
        return new \PDO("mysql:host=localhost;dbname=roundth4_rtb2", 'root', '');
    }
}
?>

then inside the class you can include the connection class:

<?php
require 'dbconn.class.php';
class headScript
{
    private $db;

    public function __construct()
    {
        $this->db = new Dbase\Dbconn();
    }

    public function headLoad()
    {
        $q = $this->db->conn()->prepare("SELECT scriptCode FROM head_scripts WHERE active != '0'");
        $q->execute();
        $q->setFetchMode(PDO::FETCH_ASSOC);
        $output = array();
        $i = 0;
        while($row = $q->fetch())
        {
            $output[$i]['scriptCode'] = "<script>\n" .$row['scriptCode']. "\n</script>";
            $i++;
        }
        return $output;
    }
}

$play = new headScript();
print_r($play->headLoad());

?>

and it should work. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Usually I search for whatever it makes me smile or that I find ironic, for example: UOGB, Chinese Man, Reggie Watts, World/Inferno Friendship Society, Magnetic Zeroes, Black Keys and many others!

cereal 1,524 Nearly a Senior Poster Featured Poster

This depends on IIS7 which caches each processed file, it is done to increase speed.. to disable caching use these instructions:

http://technet.microsoft.com/en-us/library/cc754957(v=ws.10).aspx
http://www.ehow.com/how_8532771_turn-off-iis7-caching-php.html

bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Yes, I tried that rule before posting the suggestion and it works fine, I usually use stylish into other websites to change colors or fonts. It's handy.

cereal 1,524 Nearly a Senior Poster Featured Poster

@LastMitch
if you install an extension like stylish in your browser you can add a simple rule to hide that bar:

#toolbar { display:none; }

besides I like that bar and I use it! bye! :D

cereal 1,524 Nearly a Senior Poster Featured Poster

If the server is under linux you can use dmidecode for the motherboard serial:

sudo dmidecode --type 2 |grep -i serial

For the harddisk use hdparm:

sudo hdparm -I /dev/sda | grep -i serial

this will check for the serial of the master hd, for slaves you have to check for sdb, sdc... in any case, with both commands, you need to provide a password or you have to add the Apache user to the admin group which, for security reasons, it is never a great idea.

cereal 1,524 Nearly a Senior Poster Featured Poster

Change it like this:

<?php
class myClass
{
    public $myVar="this is demo";

    public function myTextdemo()
    {
        return $this->myVar; # the problem was here
    }
}

$obj = new myClass();
echo $obj->myVar; # and here you wrote $obj->$myVar with an extra $
?>

use return to output data from a function not echo and use $this inside the class functions, otherwise the declared property will not be considered and you will get an error like Undefined variable...

http://www.php.net/manual/en/language.oop5.properties.php

bye! :)

cereal 1,524 Nearly a Senior Poster Featured Poster

From this example file I see there is a tracks block in which you have to insert each mp3 data:

<tracks>
    <item id="11">
        <title>
        <![CDATA[ Mix Track 2 ]]>
        </title>
        <artist>
        <![CDATA[ feat. Eo ]]>
        </artist>
        <!--
        if you want this item to have a different artist(for example featuring artist write the text in this tag
        -->
        <duration>00:31</duration>
        <!--
        define this only if is the correct duration, otherwise it will make the song to jump incorrectly
        -->
        <buy price="0.99" url="http://www.flabell.com" target="_blank">Buy</buy>
        <!--
        if you want this item to have a different text then the general text, write the text in this tag if the url is empty then the button won't appear
        -->
        <song>content/songs/song1.mp3</song>
        <!--
        if you want to use RTMP streaming use this "song" tag like below
        -->
        <!--
        <song streamer = "rtmp://domain.com/app/">mp3:streamPath</song>
        -->
    </item>
</tracks>

The parent block is used to determine the album details:

<mp3gallery>
    <albums startAlbumNo="">
        <album id="1">
            <author>...</author>
            <image>content/images/albums/50 Cent.jpg</image>
            <name alsoInList="true">...</name>
            <caption>...</caption>
            <link>http://www.themesbell.com</link>
            <target>_blank</target>
            <!--...-->
            <buy price="9.99" target="">http://www.themesbell.com</buy>
            <!--...-->
            <tracks>...</tracks>
        </album>
    </albums>
</mp3gallery>

In order to add a song to an album you have to add an item block to tracks. From what I see in the linked file, each item has an id number and this cannot be repeated not even into another album of the same xml file, or at least this is what I see from this example. This is a bit strange behaviour, I would expect to reset the item …

cereal 1,524 Nearly a Senior Poster Featured Poster

If you add a function to the controller as my previous example:

/controller_name/ajax_category/category_id

you can change ShiftChanger() to this:

ShiftChanger('shiftcontainer','ajax_category',value);

and at line 28 change:

AjaxObjects[ajaxIndex].requestFile = url+"/"+id;

then I think it should work, the resulting link will be something like: /categories/ajax_category/12

cereal 1,524 Nearly a Senior Poster Featured Poster

Unfortunatelly I cannot test, but try this:

$stmt=OCIParse($conn,'SELECT * FROM USERS where USER_NAME = :username');
ocibindbyname($stmt,':username','USER_1');
oci_execute($stmt);

Or try to use single quotes to wrap values:

$stmt=OCIParse($conn,"SELECT * FROM USERS where USER_NAME = 'USER_1'");

you can also add ocierror() which will output more details about the errors. Besides this I cannot help much more, hope someone else will give you a better answer, bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

I'm not sure this will help but here is missing the ending single quote:

$stmt=OCIParse($conn,'SELECT * FROM USERS where USER_NAME = "USER_1"');
cereal 1,524 Nearly a Senior Poster Featured Poster

Change this part:

$imgdata[0] = $width;
$imgdata[1] = $height;

with this:

$width = $imgdata[0];
$height = $imgdata[1];

bye!

Khav commented: The awesome helper of all time~Khav +1
cereal 1,524 Nearly a Senior Poster Featured Poster

Post the code and the full error, bye.

cereal 1,524 Nearly a Senior Poster Featured Poster

Change that echo with:

while($row = mysql_fetch_object($data))
{
    echo $row->Column1;
}

bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

The problem is that $results is not an array. With ocifetch() you get the next row from a query into internal buffers so, you get a single part of the result set, try ocifetchinto(), you can read an example here:

Or try to use ocifetchstatement() which is the alias of the php5 function oci_fetch_all() and:

Fetches multiple rows from a query into a two-dimensional array. By default, all rows are returned.

A note: in order to count the rows use ocirowcount(): http://www.php.net/manual/en/function.ocirowcount.php

bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Hi,
inside the controller create a function to retrieve the sub-category, and then point your javascript to that link, I'm supposing you will use ajax for this. So inside the controller you write a simple function:

public function get_subcat()
{
    $cat = $this->uri->segment(3);
    $this->db->where('category',$cat);
    $d['query'] = $this->db->get('table_to_query');
    $this->load->view('subcat',$d);
}

inside the view you can return plain text or json, in this example you will get json:

<?php
if($query->num_rows() != 0)
{
    $result = array();
    foreach($query->result() as $row)
    {
        $result[] = $row->subcategory;
    }

    json_encode($result);
}
?>

to access the data just point the ajax call to /controller/get_subcat/category_name

cereal 1,524 Nearly a Senior Poster Featured Poster

You can build a restful api: http://en.wikipedia.org/wiki/Representational_state_transfer this will allow you to connect to your database. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

The first argument of fnmatch() is the pattern to match, but this variable is not defined inside the function, so this can be a problem, the same seems to happen with $parameters at line 7.

But a part that, what kind of error do you get?

Try to place some echoes or die() inside each level of the function to get the exact point where the error occours, or add error_reporting(-1); at the top of the script to get the output errors.

cereal 1,524 Nearly a Senior Poster Featured Poster

Use strtotime(), you can do it like this:

$date = date('Y-m-d', strtotime($_POST['date'])) . ' 00:00:00';

And use a datetime field, since the timestamp:

The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

http://dev.mysql.com/doc/refman/5.1/en/datetime.html

bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, when you've tried this on your hosting did you got any errors? If yes, can you paste the output here? I suggested you this test just to check if the connection with the database of the hosting was working fine.

Otherwise post your code or at least a simplified version of it in which the problem is occurring. If I don't understand which kind of error you get I cannot help.

cereal 1,524 Nearly a Senior Poster Featured Poster

That can happen if you run a command like this one:

sudo echo "90" > /proc/sys/vm/swappiness

So, try this:

echo "90" | sudo tee /proc/sys/vm/swappiness

If you still get an error then check file permission, user and group:

ls -l /proc/sys/vm/swappiness

and post back here, maybe someone else will give you a better support. Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Besides sysctl.conf you have to edit /proc/sys/vm/swappiness, just replace with 90. Then you can use sudo swapoff -a and sudo swapon -a to load the new value without rebooting.

cereal 1,524 Nearly a Senior Poster Featured Poster

I suggest you to create a simple file and try the connection and a query to your database, something like this:

<?php

# config parameters
$host = '';
$user = '';
$pass = '';
$db = '';
$table = '';

$conn = mysql_connect($host,$user,$pass);
if (!$conn)
{
        die('connection error: ' . mysql_error());
}

mysql_select_db($db, $conn) or die('database error: '.mysql_error());

$q = mysql_query("select * from $table") or die('query error: ' .mysql_error());
echo 'result: ' . mysql_num_rows($q);
?>

This is very basic, try if it works and if you're in doubt, post back any error you get.
P.S. remember to set the correct config parameters.

cereal 1,524 Nearly a Senior Poster Featured Poster

If these connections are related to httpd service then check the access.log and the error.log of your web server, if you are using Apache then go to /var/log/apache2/. From there you can read what kind of requests are done and if there is something strange.

Use nslookup to check the source IP, it could be a spider, if that is the problem then you can use the robots.txt file to stop connections.

Otherwise in order to block an IP you have to add a rule to the server firewall, you can use iptables or the ufw interface which is the same but easier. Check the documentation and be careful to not block ssh access to your IP:

cereal 1,524 Nearly a Senior Poster Featured Poster

Ok, try also to set CURLOPT_FORBID_REUSE: http://php.net/manual/en/function.curl-setopt.php
For example if you have a group of files to download from the same source, add this option only in the last loop, so curl can use the previous connection and your script should execute faster.
Bye!

cereal 1,524 Nearly a Senior Poster Featured Poster

Maybe --mat-time flag can be helpful for you: http://curl.haxx.se/docs/manpage.html#-m

cereal 1,524 Nearly a Senior Poster Featured Poster

Regarding the first package download the latest: http://zlib.net/zlib-1.2.7.tar.bz2
For the Man-pages check here: http://www.kernel.org/pub/linux/docs/man-pages/