minitauros 151 Junior Poster Featured Poster

Well it doesn't hurt does it? :)

minitauros 151 Junior Poster Featured Poster

You mean the required cooperation? That means that I have over 5 classes that all make use of each other's functions. So what I do now is I global the var name of the required class in a class's constructor and save it to $this->globalclassname to make it available through the whole class. Probably not the cleaneast solution, but it does work and it works fine for now :).

minitauros 151 Junior Poster Featured Poster

Well that does add something to my knowledge, thanks :)! After a few moments of thinking, I decided I'll just make all my classes globally available so that I can use them wherever I want. There's such a close cooperation between all the classes, I couldn't think of a better way.

minitauros 151 Junior Poster Featured Poster

True that! You'll probably wanna use AJAX, then :).

minitauros 151 Junior Poster Featured Poster

I just started wondering.. I have a bass class, let's say a class called Framework. This class contains a lot of functions and sets a couple of variables that are used inside other classes. What would be the most efficient way to access these variables from inside other classes? Should I have them extend the Framework class, or should make the variables available in some other way?

Side question: if I have 5 classes that all extend the Framework class, does that mean that the Framework class is instantiated and constructed 5 times during the execution of the script?

minitauros 151 Junior Poster Featured Poster

No I mean his form's target is _blank, which means a new window will open and the original window will stay to exist to execute another form submission. At least, that MIGHT be so, I've never tested it, but that's why I came up with the idea :p.

minitauros 151 Junior Poster Featured Poster

Yea but you're being sent to a new tab, right? So the original tab will remain to exist :).

minitauros 151 Junior Poster Featured Poster

No idea if it works, but maybe this is an idea?

function buttonOne()
{
    document.Form1.target = "_blank";

    // Submit data to first domain.
    document.Form1.action = "http:/my domain 1/action.php"
    document.Form1.submit();

    // Submit data to second domain.
    document.Form1.action = "http:/my domain 2/action.php"
    document.Form1.submit();

    return true; 
}
minitauros 151 Junior Poster Featured Poster

If you want to place <b> tags around every element in your array, you can use the following:

<?php
function makeBold(&$input)
{
    // The & sign is used to make live changes to the input value.
    $input = '<b>' . $input . '</b>';
}

// Execute the function for every element in every dimension of your array.
array_walk_recursive($your_array, 'makeBold');
minitauros 151 Junior Poster Featured Poster

Hey LastMitch, thanks for your reply! The point is: I want to be able to use "localhost" everywhere, as I'm used to, instead of "127.0.0.1". Many users reporting the same slow mysql_connect problem have been told to edit their hosts file and add the line I was talking about to it. For me, the line was already there, so it did not solve my problem. Anything else I can do to get rid of having to type 127.0.0.1 instead of "localhost"? :)

minitauros 151 Junior Poster Featured Poster

Hello! I've recently installed Windows 8 and since that moment my XAMPP installation has been acting a bit weird it takes over a second to establish a mysql connection (mysql_connect) where it used to take less than 0.01 seconds.Timed:

Timer 1 (mysql_connect): 1.02864
Timer 2 (select_db): 0.00023

I have found a solution: instead of using mysql_connect('localhost'...) I use mysql_connect('127.0.0.1'...). New timers:

Timer 1 (mysql_connect): 0.00446
Timer 2 (select_db): 0.00023

However, I want to be able to just connect to localhost! :) I've checked my hosts file. It does contain a line saying "127.0.0.1 localhost" and the line "::1 localhost" (the ipv6 variant) has been commented out with a #. It's just not working. Any suggestions?

minitauros 151 Junior Poster Featured Poster

For the first problem:

<?php
$q = 'SELECT anything
    FROM copyright
    WHERE copyr_md5 = "' . mysql_real_escape_string($md5check) . '"
    LIMIT 1';
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);

if($fetch)
{
    // A record that matches $md5check has been found.
}
?>

For the second problem:

<?php
$q = 'SELECT field1,
    field2,
    field3
    FROM table
    WHERE md5checksum = "' . mysql_real_escape_string($md5check) . '"
    LIMIT 1';
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);

if($fetch)
{
    // A record that matches $md5check has been found.
    $field1 = $fetch['field1']; // etc.
}
minitauros 151 Junior Poster Featured Poster

Well you could write that a bit cleaner :). For example I'd use a switch (but maybe you should think about putting all this in a database).

<?php
$diagnostics = $_POST['diagnostics'];
$room = $_POST['room'];

if($diagnostics == 'Plomb CREP')
{
    switch($room)
    {
        case '95':
            $price = 120;
            break;
        case '100':
            $price = 140;
            break;

        // Etc.
    }

    echo 'Price for Plomb CREP: ' . $price . '<br/>';
}
else
    echo 'Diagnostics price: ' . $pieces . '<br/>';
?> 

But I'm still not 100% sure what you're trying to achieve. Maybe I can help you better if you'd be a little bit more specific :).

minitauros 151 Junior Poster Featured Poster

I once ran into Felipe Ribeiro's spelling corrector class. It can do spelling suggestions like "did you mean... ?". I think it can be useful in this case. You can find it here. It's a pretty nifty piece of work :).

minitauros 151 Junior Poster Featured Poster

Thanks guys for the advice! I really appreciate it :). My main focus would be on web-applications. That does not necessarily mean web-BASED applications, rather just any application that supports multiple users to work with it and be connected with each other (directly or indirectly).

I've never thought about python, I'll certainly check it out, thanks! After some more research and after what you said, my first choice would now be Java. It sounds like a language with a good solid basics for the future (for if I ever decide I want learn another language). Thanks again for the advice!

minitauros 151 Junior Poster Featured Poster

Hello everyone. I was wondering if you could help me with an issue. I currently know pretty much about web development in PHP/Javascript and I would like to start learning a new language (in which I can preferably also do some web development). Which language would you recommend for me to start learning?

For as far as my knowledge goes I am now thinking about Java and ASP.NET. For as far as I've heard, Java is supported on many platforms and a good language to learn the basics of, and ASP.NET is also a pretty popular language at the moment. Any suggestions on this? Thanks!

minitauros 151 Junior Poster Featured Poster

Yea, as adam says, you can try if specifying the full path to your css file instead of a relative path works.

minitauros 151 Junior Poster Featured Poster

You're welcome!

minitauros 151 Junior Poster Featured Poster

What happens when you include a file, is that the contents of the file that is being included are loaded on the place where your include function is executed.

So, for example, when you have code like:

<html>
include 'header.php';

... blablabla ...
</html>

And header.php looks like this:

<head>
... blablabla ...
</head>

the output to your browser will be as follows:

<html>
<head>
... blablabla ...
</head>

... blablabla ...
</html>

You should double check if the link to your CSS file is working :). You don't need separate CSS files.

minitauros 151 Junior Poster Featured Poster

Sure it will :). You put a code on every page of your website that inserts a record into your pageviews table each time a page is loaded, for example:

INSERT INTO pageviews (ip_address, time_of_pageview) VALUES ("' . $ip_address . '", NOW())

Then, to calculate the number of users that are currently online, you could execute a query like this:

SELECT COUNT(DISTINCT ip_address) AS number_of_users_online FROM pageviews WHERE time_of_pageview > NOW() - 60 * 60

minitauros 151 Junior Poster Featured Poster

Uhuh yea, that's what I mean. Of course you need a table with records to obtain results from. You could also replace the BETWEEN with, for example, something like "WHERE time > NOW() - 60 * 60" to find all users that have been active in the last hour.

minitauros 151 Junior Poster Featured Poster

Oooooh! Well in that case you could create such a same table and then, instead of counting the total number of page loads in the last x hours, you could do something like:

SELECT COUNT(DISTINCT ip_address) FROM pageloads WHERE time BETWEEN ... AND ...

minitauros 151 Junior Poster Featured Poster

If you want to obtain just the name of the file, you could also do it as follows:

<?php
    $file = 'folder1/folder2/image.jpg';
    $file_name = substr($file, strrpos($file, '/') + 1, strrpos($file, '.') - strrpos($file, '/') - 1);
    echo $file_name; // Will output "image".
minitauros 151 Junior Poster Featured Poster

For pageviews, just insert a new record into a table called, for example "pageviews", including at least the date and an ID, every time a page is loaded. Do this for every page, and if you want to know the total of pageviews for a certain period, then SELECT COUNT(...) FROM pageviews WHERE date BETWEEN ... AND ...

minitauros 151 Junior Poster Featured Poster

Yes sir it appears to be correct :). See this page for more information.

minitauros 151 Junior Poster Featured Poster

Well, my advice is: why reinvent the wheel? Google offers a great application for tracking your website's visitors and it's called Google Analytics. It's free to use. You should try it :).

If you want to keep track of the number of visitors on your website you will have to think about the following: do you want to track unique visitors or do you not? Then you could insert a record for each time a certain IP visits your website, except (in case you want to track only unique visitors) if the IP has already been inserted in the past X hours, for example.

minitauros 151 Junior Poster Featured Poster

Well, I guess that means you're going to have to save all your menu item information in a database and retrieve it whenever your menu is loaded. Is that enough information? ;)

minitauros 151 Junior Poster Featured Poster

I think you're looking for something like this (still to be worked out, of course):

<?php
for($i=0; $i<count($records); $i++)
{
    $record = $records[$i];

    // Set data.
    $password = $record['password'];
    // etc...

    // Mail the user his login info.
    mail(...);

    // You're done!
}
minitauros 151 Junior Poster Featured Poster

Maybe you could try something like:

href="mailto:?subject=Welcome to my site&body=<?php echo urlencode($your_post); ?>"

minitauros 151 Junior Poster Featured Poster

Well your if(isset($_POST['submitRec'])) is inside your if(isset($_POST['submitButton'])) statement, so in order for it to work, $_POST['submitButton'] must be set. This is probably not the case when you submit the second form, so what I think should solve your problem is placing the if() construction that contains the Javascript warning outside its parent if() construction :).

scholarwithfire commented: Thanks it worked :) +0
minitauros 151 Junior Poster Featured Poster

Yea I noticed :). But mktime(24, 0, 0, 10, 28, 2012) returned exactly the same as mktime(0, 0, 0, 10, 29, 2012), and both are not working.. :( I live in Holland and we have daylight saving time here as well, but wouldn't that mean that an hour should automatically be added to the first timestamp as well instead of only to the second one?

Edit: Oh nvm, I get it, daylight saving time ends just before my end date.. Right.. Thanks ^^! Good to know.

minitauros 151 Junior Poster Featured Poster

Hello there. I am kind of confused. In PHP I substract two unix timestamps from each other.

The first: mktime(0, 0, 0, 10, 22, 2012)
The second: mktime(24, 0, 0, 10, 28, 2012)

For as far as I know the time difference between these two timestamps is exactly 7 days. What I get, however, when I substract the second from the first ($time_difference = $second_timestamp - $first_timestamp) and then divide it by a week (60 * 60 * 24 * 7) is not 1, but 1.0059523809524 (which equals 1 week and 1 hour)!

Wtf?! Can someone please explain? :p

minitauros 151 Junior Poster Featured Poster

Where do you set $id? Just print your query (echo $query;) and check if all data is in there.

minitauros 151 Junior Poster Featured Poster

Googling I found something that might help you:

Ajax in the traditional sense is XMLHttpRequest, which does not allow you encode and send local files to a server.

The common ways of doing uploading through "ajax" means, is to either use a Flash swf to handle the uploading on the same page, or to use a form that has a target of an invisible 1x1 iframe. You have some Javascript show a uploading spinner or whichever. After the file is uploaded, make the server return some Javascript to the iframe like

<script type="text/javascript">
top.MyProject.doneUploading();
</script>

top will allow you to call Javascript in the regular page. In order for that to work though, you must make sure the iframe has submitted to the same domain that the top document is located at.

(From this link). Some other info about Javascript / PHP uploading using HTML5 can be found here.

minitauros 151 Junior Poster Featured Poster

I guess the big question here is: what kind of data are we talking about? If we're talking about highly private data, like money transfer records etc., you could consider encrypting it, but, if it is data that is publically available to anyone anyway, why would you even bother encrypting it?

minitauros 151 Junior Poster Featured Poster

Maybe put /client/ in front of the index.php? No idea though, not so good with URL rewrites :). Woops, double post, sorry!

minitauros 151 Junior Poster Featured Poster

Maybe put /client/ in front of the index.php? No idea though, not so good with URL rewrites :).

minitauros 151 Junior Poster Featured Poster

Mabye $row['serial'] contains some kind of apostrophe that is not allowed in that particular spot?

minitauros 151 Junior Poster Featured Poster

Can you perhaps show us the actual error that you receive? :) I don't quite understand what is going wrong right now.

minitauros 151 Junior Poster Featured Poster

You could also use the simplified version of writing to a file, the file_put_contents(file_name, file_contents) function (click here to see it on php.net) for this purpose. You could then use the input from your form to determine the file name and content.

What exactly is going wrong, by the way?

Oh, and another remark: generating a random name like that (using a random number ranging from 0 to 100) is not very secure: you will end up sometime with overwriting an existing file. If you do want to use this method of generating a random file name, I suggest checking if it already exists before you try to write to it. Because if it does already exist, you might encouter some errors in your script.

minitauros 151 Junior Poster Featured Poster

I didn't even know there was anything like an oriental or portrait lay-out in Excel, just thought that depended on the width of your cells :o?

minitauros 151 Junior Poster Featured Poster

You're welcome :). Glad you found a solution!

minitauros 151 Junior Poster Featured Poster

What you're doing is checking if the mysql query is being executed correctly. $tester will be set to true if the query could be executed, or to false if it could not. You should rather use something like: $results = mysql_fetch_assoc($tester); And then check if $results has any records. If it has, results could be found for the query that was just executed. If not, no results were found.

minitauros 151 Junior Poster Featured Poster

What about using a switch? Example:

<?php
switch($_GET['mode'])
{
    default:
    case 'index':
        include 'includes/index.php';
        break;

    case 'login':
        include 'includes/login.php';
        break;

    // Etc...
}
?>
minitauros 151 Junior Poster Featured Poster

It looks like what you typed is correct. If you have a form with an <input> field that has the "name" attribute set to "name", then its content is stored in $_POST['name'] (capital letters in the $_POST part!), on the page that is loaded by submitting the form. So it will only be available on the page that is loaded when the form is submitted, not after that! If you want to keep using that data, you can consider storing it in session variables (here's the link to sessions on php.net: http://php.net/manual/en/session.examples.basic.php).

So, shortly summarized, you can access the data like this:

<form action="" method="post">
<input type="text" name="name"/>
<input type="submit"/>
</form>

<?php
// Echo the data the user has submitted. The form method was "post", so the data is stored in
// $_POST. If the method had been "get", the data had been stored in $_GET.
echo 'You have just submitted a form. The name you entered was: ' . $_POST['name'] . '.';

// Optionally store it in a variable that will only available on this page.
$name = $_POST['name'];

// Optionally store it in a session variable, so that it will also be available on other pages.
// If you want to use this, you should use the session_start() function in the first lines
// if your document.
$_SESSION['name'] = $_POST['name'];
?>
minitauros 151 Junior Poster Featured Poster

Well if you want to execute an action you will always have to load a new file or reload the current file. The only exception is if you use AJAX to dynamically load a file (you know, like for example the search completion that Google uses, that's AJAX).

So, if you for example have a file called index.php, which contains a login form, and you want the user to stay on index.php even after he has logged in, you have several ways of achieving that. The first is to redirect the user as soon as he submits the form. For example you could redirect him to login.php, set a $_SESSION variable there that says he has been logged in, and then redirect him back to index.php, which then recognizes the $_SESSION variable and displays data that requires the user to be logged in.

Another way is to redirect the user to index.php?login=true, for example. Index.php then checks if $_GET['login'] has been set, and if it has, it checks the login. If the login then is correct, some new data is loaded, and if it is not, a login error is loaded. These are all examples, of course, just to show you *some* possibilities to achieve what I think you want to achieve :).

minitauros 151 Junior Poster Featured Poster

It means that your select query isn't returning any results, probably due to some kind of error. Maybe you could try to output a mysql_error()? Just put the following statement before the return functions: echo mysql_error(); and see what it does.

minitauros 151 Junior Poster Featured Poster

Every time the user sends a gift, you can insert a record of that into a tracking table. Then you can retrieve all gifts that were sent in the past 24 hours. E.g. SELECT COUNT(id) FROM gifts WHERE time_sent < 24 hours.
Then if the count is two or more, disable the sending of gifts.

So you select all gifts that were sent in the past 24 hours, and then you count those results. If the user has not yet sent 2 gifts, he may send another one :). Hope this helps?

minitauros 151 Junior Poster Featured Poster

Hey there. I think the array_walk_recursive function might work for you. Check it out here on the php.net website: http://www.php.net/manual/en/function.array-walk-recursive.php

You'll have to write a custom function to check the values of your array keys, though.

minitauros 151 Junior Poster Featured Poster

No I have not :). What does that do? Change the owner of the files? Thanks for the reply!