Jump to content
xisto Community

Spectre

Members
  • Content Count

    1,034
  • Joined

  • Last visited

Everything posted by Spectre

  1. In my opinion, it is usually a better idea to specify the value of hypertext references (the 'href' element of an 'a' HTML tag) relative to the root directory of your site rather than relative to the current directory - such as, for example, in '/folder/subfolder/index.html', use '<a href="/folder2/page.html">' rather than '<a href="../../folder2/page.html">'. It may sometimes mean adding a bit more text, but it also means it is easier for clients to locate files.Anyway, if you are generating your menu dynamically, it would probably be a better idea simply to 'echo()' (or otherwise send as output) the HTML code from the PHP script being used. I don't know why you would need to re-create the menu every time it is viewed, but you obviously have your reasons.
  2. That's what dogomchawi is saying. The entire query must be enclosed in double quotes, but field values must be enclosed in single quotes within the double quotes (or it can work the other way, provided you specify either constant values or add them outside the quotes). MySQL requires that string-like values be enclosed in quotes to determine delimitation - numeric values are, obviously, only going to contain numbers (and possible a decimal place), whereas strings can contain spaces and any other number of 'special' characters which MySQL may mistake as indicating it should move to the next field assignment.I hope that makes sense. Oh, and you should -always- use single quotes where possible. Strings contained within single quotes are not checked for variable references etc, so they are processed much more quickly (even if a string contained within double quotes doesn't contain any variable names at all, it is still checked for them as well as other escaped characters, which takes processing power and time).
  3. This pattern should match almost any Roman numeral below L/50 (it is unlikely you will ever encounter anything beyond, say, 10th/X generation names). /\b(i+|i+[vx]*?|v[i]*?|x+[vi]*?)\b/ei Here's a quick example (the names are, of course, randomly chosen). Note that the 'strtoupper()' function is being evaluated as PHP code and is enclosed in quotes. <?php$names = array( 'john sMith iv', 'Richard jones Iiv', 'JOE NOBODY II', 'Viva vivi ixen ivan III', 'Person XI', 'person xv');$pattern = '/\b(i+|i+[vx]*?|v[i]*?|x+[vi]*?)\b/ei';for( $i=0;$i<count($names);$i++ ) { $name = ucwords(strtolower($names[$i])); $string = preg_replace($pattern, 'strtoupper("$1")', $name); $names_p[$names[$i]] = $string;}print_r($names_p);?> Outputs:
  4. The $_SERVER variable always contains an index 'DOCUMENT_ROOT' which points to the document root of your site from the top-level directory. So using include($_SERVER['DOCUMENT_ROOT'] . '/folder/file.php'); may help.
  5. This mostly happens with listings for pseudo-search engines that are masquerading as the real deal, who allow advertisers to pay to get their results to the top. The URI contains the search terms you may be searching for, so Google sometimes ranks them for that result. Often they get dropped from Google's index - but not always.If you don't want to encounter these sites, it might be worth looking at the URL which Google displays at the bottom of each result. As OpaQue mentioned, they are usually something like x.com/search.php?search+terms - so if you see such a URL, you can simply ignore it.
  6. Regarding PageRank retrieval, no, I'm not sure at all - but in the standard Google TOS it clearly states that automated requests to the server are strictly prohibited. Whether or not that is only intended to apply the actual search results I don't know. Regarding automated link popularity checking and other such search result retrieval, yes, I do know that you can be penalized for it. The Google PageRank is shown in the Internet Explorer add-on toolbar that Google provides as well, but that's a product from Google itself. If you look at the algorithm used to encode a websites URL and retrieve it from Google's server, it is quite complex and clearly not intended for general public use outside of what Google provides.
  7. I would do something like: ...do { cout << " Please enter an odd number between 3 and 25: "; cin >> size; } while( size < 3 || size > 25 );... If this is your homework, I would suggest you do not ask for other people to solve it for you. You won't be able to post a message and wait for a reply on a forum during an exam.
  8. As useful as such utilities might be, I would imagine they are against the Google Terms of Service (not unlike automated link popularity checkers or other such utilities that extrat Google results). So I would not recommend using them on your own site too much - although nothing may come of it, it is possible that Google would drop you from their index if they were to believe you were violating their terms.
  9. After this and the 'Dr. Death' saga, one would have to start to wonder about the Australian health system, which has been hailed as being amongst the worlds greatest.
  10. I don't meant to criticize, but this isn't exactly a tutorial. Further more, references to the mail() function have been posted throughout the site on numerous occasions.
  11. There are many free hosts offering PHP, MySQL, and all the other features that Xisto offers. However, they die out within the first month or two of operation about 99% of the time. Xisto has been going strong for over a year now - which I think is the main reason people keep coming back. Nothing proves reliability more than the test of time.
  12. Well, I'm assuming this problem is more or less resolved. So for anyone else experiencing the same problem, I would recommend either not using FireFox, or using a different script. The latter is probably more realistic for most people.
  13. Spectre

    Opera opera

    Whilst I think that there are some good things about the Opera browser, there are also some downsides - one of them being that you have to pay for it (unless you are willing to put up with banner ads being displayed in the program).Anyway, this isn't at all related to SEO. So why is it posted here?
  14. Personally, I would recommend you use a text editor to modify your scripts locally, then test them on your machine before uploading. If you use Windows, Notepad should do the trick or on *nix, vi should work ok. Keep in mind that a text editor is very different from a word processor, and you obviously don't want the additional formatting a word processor would add to the script.
  15. Thanks for the feedback. I've written it how I think I would have found easy to understand when I was first starting out with PHP. It obviously isn't going to suit every single other person - but then again, nothing ever does. Hopefully there will be those who will learn a little something from it. And thanks for that, snlildude87. bluhapp, whilst I'm not offended by your question, I like to think I am 'above' plagiarizing content and attempting to take the credit for it. All the same, feel free to use any search engine to check it if you wish. I will write some more later (by which I mean, sometime in the next few years), and I will try and improve it according to your comments.
  16. I'm not exactly an expert on PHP, but I know a thing or two. Although I have attempted to write at least one tutorial myself, that's not the way I learnt it. I learnt it by setting up PHP and Apache on a box and fiddling with it until I got it right, using the PHP manual for reference. Whether or not that slowed down the rate at which I picked the language up I don't know, but I'm pretty confident with it now.
  17. I should point out that I originally put this tutorial together for another site, but decided against it and to place it here instead (because I love you guys... ~sniffle, wipe a tear away~). This tutorial should help get you started if you are just setting out into the big bad world of eb development. I have been coding in PHP for a little over a year now, and have worked on several large projects in the language - but whilst I certainly don't know everything about it, I would like to share some of the basics that hopefully will give you a bit of a kick start. ----------------------------------------------------------------------------------- Just a few quick notes to begin with: PHP can be placed in any plain-text file, but that file has to be passed to the PHP engine. This usually requires that the web server be specifically instructed to do so, because it isn't going to automatically figure out what to do. The PHP engine ignores everything outside of the <? ?> tags, sending it directly to the client as output. This enables you to embed HTML within a PHP script, allowing for maximum power when it comes to delivering web pages to users. The PHP manual is an invaluable tool of reference for any PHP programmer, regardless of their experience or skill. I find myself constantly referring to it when I forget the exact sytnax of a function or when debugging is getting me down. ----------------------------------------------------------------------------------- This tutorial covers: + Functions + Constants + if...then..else + Switch() structure + While() and For() loops Functions Functions are what carry out all the operations that need completing in order to fulfill the task(s) you designed your script for. PHP allows you to design your own functions, which can call other functions, process and modify data, and anything else you would want them to do. Functions can do whatever you want them to, and are an essential part of developing large scripts or applications which incorporate a large number of scripts. They allow you to specify a set of instructions which can be repeated at any time during the execution of your script without having to re-write them all - instead of including many identical lines of code in order to carry out the same set of instructions again and again, you simply call the function. Defining a function is easy, and you can specify which (if any) arguments are passed to it - and whether or not those arguments are optional. An argument is treated as a variable, and that variable is assigned the value of the argument. Multiple arguments can be specified for each function, but they aren't required. If an argument is optional, you can specify the default value that argument will have if it is not assigned when calling the function. // Standard function definition with no argumentsfunction MyFunction() {}// Function definition with a single required argumentfunction MyFunction( $argument ) { echo $argument;}// Function definition with multiple required argumentsfunction MyFunction( $argument1, $argument2, $argument3 ) { echo "$argument1, $argument2, $argument3";}// Function definition with single optional argumentfunction MyFunction( $argument = '' ) { // Note that '' will be the default value of $argument if no value is specified. // '' can be changed to anything of any type ('string',1,2,3,FALSE,array(),etc). if( $argument == '' ) { echo 'No argument.'; } else { echo 'Argument.'; }} In the above example, the function MyFunction() is declared. This means that anywhere in the script that defined the function - as well as any other scripts used via include() or require() - can access this function whenever they need to. A custom function can return a value if required, but it doesn't have to. The value is returned by using the 'return' statement, which is optionally followed by a variable or value which will be the result of the function. A return statment results in the immediate termination of that particular function, but it does not terminate the entire script - if exit() or die() are called from within a function, the entire script is halted, but the return statement only affects the function it is within. // Returns nothing - simply exits the function.function MyFunction() { return;}// Returns the boolean value TRUEfunction MyFunction() { return true;}// Returns a substring of the argumentfunction MyFunction( $argument ) { return substr($argument,0,3);} Constants A Constant is similar to a variable, however, it's value remains constant (hence the name) - that is, it doesn't change. Constants are very useful for use in scripts where the same value will need to be accessed many times without changing. phpBB, for example, defines a constant 'IN_PHPBB' with the boolean value TRUE, which it then checks for in other scripts so that it knows it is being accessed correctly. Constants are defined using the define(constant,value); function, and unlike variables, are used without the $ symbol prefix: define('CONSTANT','This is a constant');echo(CONSTANT); Like variables, constants are case sensitive, meaning that 'CONSTANT' is different to 'Constant'. Once declared, their value cannot be changed and they cannot be 'destroyed' (eg. via the unset() function). if...then..else If statements are something that simply cannot be avoided or ignored in programming - in PHP or otherwise. They allow you to ensure that everything is running exactly the way it is supposed to be - and if it isn't, then you can do something about it. A basic if statement consits of a condition and a statement or series of statements. The condition is evaluated first, and if it returns TRUE, then the statements are processed. You can also use the Else and ElseIf statements to instruct the script on what to do if the initial condition is not met. // A simple if statementif( condition ) echo 'True'; Now whilst the condition must be TRUE, that does not at all mean that it must be a boolean value being compared - it simply means that the overall condition must be true. For example, if( $variable > 3 ) would return TRUE if the value of $variable was larger than 3, but FALSE if it were 3 or below. It is important to remember that a double equals sign is used for comparison, as opposed to a single equals symbol used for assigning a value. If only one statement must be processed as the result of a condition, then it can simply be placed on the next line underneath the if statement - however, if you need to specify more than one statement, you can enclose them in curly braces. // A simple if statement with more than one resulting statementif( condition ) { echo 'First statement.'; echo 'Second statement.'; echo 'Third statement.'; echo 'And so on.';}// Using Elseif( condition ) { echo 'True';} else { echo 'False';}// Using ElseIfif( $variable > 100 ) { echo 'Over 100';} elseif( $variable < 25 ) { echo 'Under 25';} else { echo 'Between 25 and 100';} Get the picture? More than one condition can be evaluated within a single if statement. You can either require that all conditions meet the same result, or that one condition meet one result or another condition meet another result. // Requires that all conditions are trueif( $variable1 == 123 && $variable2 == 'xyz' ) { statements;}// Requires that either condition be trueif( $variable1 == 123 || $variable2 == 'xyz' ) { statements;}// Any number of conditions can existif( condition1 || condition2 || condition3 || condition4 )if( condition1 && condition2 && condition3 && condition4 )// Required condition blocks can be placed in brackets// The following would result in true if both condition1 and condition2 were true, or if both condition3 and condition4 were true, or if all conditions were true.if( ( condition1 && condition2) || ( condition3 && condition 4 ) ) It is also possible for the condition to be evaluated as false - that is, it equals TRUE only if the requirement is FALSE. This is done by using the exclamation mark (the !) preceeding the condition. Kind of hard to explain, so here's an example: // If $variable is not equal to 3...if( $variable != 3 ) { statements;} Functions can be included as a part of the condition as well. The result of the function or the value that it returns is what is used as part of the evaluation. // If MyFunction($variable) is equal to 3...if( MyFunction($variable) == 3 ) { statements;}// If the result of MyFunction() is anything other than true (note the !)...if( !MyFunction() ) { statements;} It is also possible to set explicit condition requirements by using an additional equals symbol. As you may know, the numerical value 1 is also treated as TRUE, and 0 as FALSE - however, if you only want the boolean value TRUE to be treated as TRUE and not the numerical value of 1, you can do so. // In this if statement, the condition would be true.$variable = 1;if( $variable == true ) { statements;}// However, here, it would be falseif( $variable === true ) { statements;}// Here it would be true, because the absolute value of $variable is not TRUEif( $variable !== true ) { statements;} In some situations, it is more practical to use a conditional operator than a full if statement. A conditional operator allows you to turn a long if statement into a single line of code, however, it reduces the ability of other programmers (or even yourself) to read the script, and sometimes isn't suitable. It is most useful for quickly assigning a conditional value to a variable, and works like this: condition ? true : false; where TRUE is the result of a true condition and false the opposite. // An if statementif( $variable == 5 ) { $variable = 3;} else { $variable = 8;}// Exactly the same statement in the form of a conditional operator$variable = ($variable==5) ? 3 : 8; As you can see, a conditional operator is much more compact than an if statement. More than one condition can be specified by using multiple conditional operators within each other. It can get a bit complex, but here is a quick example: // If statementif( $variable1 == 5 && $variable2 == 1 ) { $variable1 = 6;} else { $variable2 = 7;}// Conditional operator$variable1 = ($variable1==5) ? ($variable2==1) ? 6 : 7 : 7; As you can see (sort of), the two conditions are still there, as are the two possible results. Switch() The Switch() structure allows for you to take a different action depending on the value of something. Although not always the best option, it can sometimes replace the need for a series of if statements that evaluate the same value but require a different result. For example: $variable = 23;// Here, $variable is checked to see if it equals 12, 18, 23, or something else.if( $variable == 12 ) { statement1;} elseif( $variable == 18 ) { statement2;} elseif( $variable == 23 ) { statement3;} else { statement4;}// Switch can replace all of the if and elseif statementsswitch( $variable ) { case 12: statement; break; case 18: statement2; break; case 23: statement3; break; default: statement4;} Keep in mind that the 'break' statement must be used after the final statement in each respective case to inform the script that it has met its condition and carried out the required statements. The 'default' case is what will occur if none of the other cases match, and doesn't have to be included. Any variable type can be used - string, boolean, numerical, whatever. While() and For() loops Loops are an easy way for a set of statements to be repeated until a requirement or condition is met. The conditions can be exactly the same as in If statments, so I won't re-cover all of that. Keep in mind that you can break out of a loop at any time by using the Break statement (which is the equivalent of the return statement in a function). The While loop is probably the most basic and easy to use loop there is. The condition is evaluated only at the beginning of each loop (and every time the loop is repeated) - so if the condition is false at the start of the loop, but changes during the loop's cycle, it will continue until the next iteration unless additional checks are done. // The while loop syntaxwhile( condition ) { statement(s);}// Simple while loop which increments the value of $variable until it is greater than 25$variable = 0;while( $variable <= 25 ) { $variable++;} The do...while loop is exactly the same as the while loop, however, the condition is evaluated only at the end of the loop. This means that at least one instance of the loop will occur, even if the condition is never true. // The do...while loop syntaxdo { statement(s);} while ( condition );// Same as the while loop shown above$variable = 0;do { $variable++;} while( $variable <= 25 );// The value of $variable will still be incremented, even though the condition is true from the start.$variable = 26;do { $variable++;} while( $variable <= 25 ); Both while and do...while loops only run while the condition is true, but as I said, only check the condition once for each iteration. The For loop is slightly more advanced than both the while and do...while loops, and is a bit more difficult to explain. The basic syntax is something along the lines of: for( expression1; condition; expression2 ) { statements;} Now, let me try and explain what each of the three arguments mean. The first argument is an expression that is only executed the first time the loop is run. It doesn't matter how many times the loop repeats itself, the expression will never be repeated again in that instance of the For loop. It is most often used for assigning a value to a counter which is used again in the condition. The condition can, once again, be anything, and is checked at the beginning of every repetition of the loop. The final argument is a second expression which is executed on every iteration at the very end (similar to the do...while loop). The most common usage for the For loop is to execute a set of statements a certain number of times: // This will loop 25 times. It works by assigning a value of 1 to the variable $i, then looping until it is equal to or greater than 25, incrementing it by one on each loop.for( $i=1;$i<25;$i++ ) { statements;} This is useful for looping through arrays and string offsets and the like. Now, the tricky thing with the For loop is that any of the conditions can be 'nothing'. You could, if you wanted to, simply have for( ; ; ) and it would still work fine (however, the loop would repeat indefinately until explicitly stopped). This allows you to place your own set of condition evaluations within the For statement in whichever way you like, and you can use the Break statement to stop the looping at any time. You can include any number of loops within any number of other loops, and different types of loops can exist within each other. Here is an example (you probably wouldn't do this, but it demonstrates what you can do if you need to): // The for loop would be executed 100 times, which would on each loop execute the while loop 100 times, of which each iteration would execute the do...while loop 100 times.for( $i=0;$i<100;$i++ ) { $a = 0; while( $a<100 ) { $a++; $b = 0; do{ $b++; } while( $b<100 ); }} ----------------------------------------------------------------------------------- To be continued...
  18. I can see your cPanel username in your profile.However, I don't think this is really a huge problem. Most often, a users cPanel username reflects either their web site name or forum name. It isn't exactly highly confidential information - provided you have a strong password, no one is going to be able to access your account.The only way anyone can 'break in' is via repeatedly trying to access the server with your user name and a password (either generated or from a list). Such activity should be picked up and delt with, and it is unlikely you will be at all affected.
  19. In my opinion, it would be better if you posted the details here, so as to allow other members to learn from it and not have to encounter the same problems again. However, if you would really rather not put it out in the public arena, feel free to PM me the details. As I said, though, if possible, I think it would be better were it to remain public.
  20. If you are using Windows XP, chances are the filesystem is NTFS - and Windows 9x/ME DOS won't recognise it. You will have to clear the partition with FDISK first, create a FAT32 partition, and then format it. But I wouldn't recommend doing this unless you know what you're doing. Besides, it should be possible to start Windows XP setup from a bootable floppy disk with CD-ROM support without needing to format your HDD beforehand. What BIOS have you got? It might be worth sniffing around the manufacturer's website for any updates they may have released, or for information on booting from the CD.
  21. Heh, I remember back when we reached 500 members, and then finally 1,000. It was quite a milestone at the time.Anyway, well done to site staff for keeping 5,000 people coming back to Xisto.
  22. Did you try the method I mentioned? You can't use '.' (a full stop) to append to an array, only to a string.In the code I posted, $array is being initialized as an array - and then assigned the values of an array later. Meaning that it should be considered an array.Try using is_array($array); to determine if it is an array and use print_r($array); to recursively print the values in the array.
  23. I would appreciate it if you would remove or unstick the thread I originated and post your version as a new one. Regardless of whether or not I agree or disagree with what you may be saying, it isn't me saying it, and I would rather it not be represented in such a way. Thanks.
  24. Hmm, I don't know of any such library, but basic HTTP headers aren't difficult to construct. Example: char *headers = "GET / HTTP/1.1\r\nConnection: close\r\nAccept: */*\r\nHost: google.com\r\n\r\n"; There probably are such libraries floating around. Have a look on SourceForge.
  25. If enclosed in double quotes, a variable will be replaced by it's value - so "Location: $location" would become "Location: x" (if x were the value of $location), but 'Location: $location' would remain exactly as is. This is why it's faster and more efficient to use single quotes where possible. However, $location doesn't seem to have been assigned a value within the code shown, so it may or may not work. But anyway, that isn't the problem. The problem is that you are sending output to the client prior to attempting to send headers. Headers are sent accompanying the first lot of data sent to the client, after which they cannot be recalled or modified. Take a look at this thread. According to the error description, the output is started in index.php on line 7. So take a look there. Oh, and on another, not-really-related note, I think the HTTP specification mentions that 3xx redirections containing a 'Location' header (which inform the client of where the page can be found) that an explicit URI must be specified (eg. website.com/file), but most clients/browsers are capable of automatic name substitution.
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.