ShawnCplus 456 Code Monkey Team Colleague

view source of 'professionally' designed scripts
bloat's the least of the problems
bad practice is about the only reason for a retrograde step.
I noted a use, not my use, personal attacks are unnecessary

I wasn't attacking you, I was just saying that if someone uses a switch-case like that then a goto is the least of their problems. It was a general statement, not an attack at one specific person.

ShawnCplus 456 Code Monkey Team Colleague

The problem with that almostbob is that if you have a switch-case with 1000 lines of code you're a horrible programmer to which the "goto" is only the stamp on your forehead to label(no pun intended) you as such.

ShawnCplus 456 Code Monkey Team Colleague

I quite like the new Dreamweaver (CS4) with its code hints and auto formatting, I know its not free but I quite like it. You also get a load of widgets such as menus and it can automatically create AJAX scripts for you. I use notepad++ as the editor on my server though as I think its small and quick to load, ideal for changing a couple of lines or adding that semicolon you forgot :P

vim is pretty old-school since it's command-line only. gVim alleviates a lot of that by adding a pretty smooth GUI along with ability to use GUI-only colorschemes that make it a LOT easier to use (I recommend Wombat, Molokai or Slate)

ShawnCplus 456 Code Monkey Team Colleague

I use gVim/vim with a bunch of custom plugins along with VCS which gives me SVN control, taglist which gives me CTRL+Click navigation for classes/functions/etc.

It has a pretty steep learning curve but once you get used to it and actually know how to use it there is no equal in power (holy war ensue.) The opponents of gVim/vim that say it isn't as powerful just don't know how to use it or get frustrated and stop.

ShawnCplus 456 Code Monkey Team Colleague

Do not use ereg or eregi functions, they are being deprecated in PHP5.3. Use preg_replace instead. And if your users' input is resulting in a MySQL error you have MUCH more to worry about than commas. Read up on mysql_real_escape_string

ShawnCplus 456 Code Monkey Team Colleague
for($i = 0, $size = sizeof($matches[0]); $i < $size; ++$i)

What are you trying to do here? You have 4 statements in a for loop, which only every takes 3.

$size = sizeof($matches[0]);
for($i = 0, $i < $size; ++$i)
ShawnCplus 456 Code Monkey Team Colleague

Once you have an array $words you can just use

$randomWord = array_rand($words);

I've been using PHP for years and I still have moments where I find out after I finish something that there is a built-in function to do it. Mainly on small things like this that shouldn't be built-in. :)

ShawnCplus 456 Code Monkey Team Colleague

In PHP5 you don't have to declare the superglobals.
To see if you're getting anything in the request you can do:

print_r($_REQUEST);

This will print out anything in $_FILES , $_GET or $_POST

ShawnCplus 456 Code Monkey Team Colleague

It wouldn't really be Apache's fault so if you could post the code that's giving you the issue that would be awesome. Also, THANK YOU for leaving PHP4, it needs to die faster.

ShawnCplus 456 Code Monkey Team Colleague
// assuming the string is called "someString"
  $words  = explode(" ", $someString);
  $index  = rand(0, count($words)-1);
  $choice = $words[$index];
ShawnCplus 456 Code Monkey Team Colleague

Just making sure, they are actually $_GET , $_POST and $_REQUEST

ShawnCplus 456 Code Monkey Team Colleague

1. Use code tags

2. <?php [b]echo[/b] imageResize... ?>

ShawnCplus 456 Code Monkey Team Colleague

It's also not doubling in the variable, you're just outputing the variable twice. You have a cout inside the if, and a cout before the return.

ShawnCplus 456 Code Monkey Team Colleague

Since it is stateless you can't persist objects across requests without storing to a file in some way be it a database, cookie(session) or some other flatfile. Not to mention maintainability is one very unimportant reason to pick OOP.

ShawnCplus 456 Code Monkey Team Colleague

Put ob_start(); in PHP tags.

ShawnCplus 456 Code Monkey Team Colleague

I'm going to have to go ahead and disagree with all of the code. Never use short tags in production. You can never know if the server you're going to move code to has short_tags enabled or not. It also makes it easier to separate code from HTML in templates.

ShawnCplus 456 Code Monkey Team Colleague

I think someone fixed a very similar problem for you before.
You cannot surround variables with single quotes, ie., '. You either have to use no quotes at all or use double (") quotes.

Read through a few sections of this http://www.w3schools.com/PHP/

ShawnCplus 456 Code Monkey Team Colleague

You'd actually want to use Apache itself to do the load balancing, not PHP. Using things like mod_proxy_balancer

This is assuming you're using Apache

ShawnCplus 456 Code Monkey Team Colleague

This is your fifth post here, use code tags. It is shouted at you at the very instant you try to post a comment. In the background of the text box, in the required reading to post on the forums and in the rules of the forums.
When you don't use code tags it makes the code extremely hard to read, thereby making your problem harder to solve. Most people just skip the post if there is no code tags and for good reason.

ShawnCplus 456 Code Monkey Team Colleague

No matter what Daniweb does to "hint" to place code tags around code no one pays attention. Could there be some sort of feature which checks a post for certain code keywords and alerts the user in some way to place code tags around code?

ShawnCplus 456 Code Monkey Team Colleague

All you had to post was the structure, not the dump of the database. I would explain to you how much is wrong with the design of the table but instead I'll give you the quick fix.

<form action="scdc.php" method="post" name="chooser">
  <label>Select Parish </label>
  <select name="chooser" id="chooser">
    <option value="Abington Pigotts">Abington Pigotts</option>
    <option value="Arrington">Arrington</option>
    <option value="Barbraham">Barbraham</option>
    <option value="Balsam">Balsam</option>
    <option value="Bar Hill">Bar Hill</option>
    <option value="Barrington">Barrington</option>
    <option value="Barton">Barton</option>
    <option value="Bassingbourn-Cum-Kneesworth">Bassingbourn-Cum-Kneesworth</option>
  </select>
  <input type="submit" name="select" value="select">
</form>
$sql_query = "SELECT * FROM base_data WHERE ParishName LIKE '$chooser'";
ShawnCplus 456 Code Monkey Team Colleague

There is no way to detect a user leaving your site without javascript. You can't do it serverside since in they leave they won't be interacting with your server :)

ShawnCplus 456 Code Monkey Team Colleague

Just look at the error

Invalid query: Unknown column 'type' in 'where clause'

There is no type column to perform the where clause against.
Show us the layout of the table( what are the columns in base_data?)

ShawnCplus 456 Code Monkey Team Colleague

Your query might be failing. Use

$result = mysql_query($sql_query,$conn) or die('Invalid query: ' . mysql_error());
ShawnCplus 456 Code Monkey Team Colleague

that's pretty much it. It's usually better to use absolute paths ie., /srv/www/public_html/includes/fetch.php but on shared hosting that might not be an option so ../file.php works just as well.

ShawnCplus 456 Code Monkey Team Colleague

obfuscation implies protection,
modifying may stop the script,
with levels of 'stop' available to the author.
It is easy to check elsewhere for a particular string of Hex,
without bothering to write the php, code can,
if not exist substring(mycopyright) in footer.html
{
mysql drop table all
die copyright has been breached
}

Once again, obfuscation is in no way a form of encryption. If you correctly reverse engineer obfuscated code you have the original code as the author wrote it. There is nothing the author can do to shut it down since you have the code. You can modify the code to not "phone home" or do any other form of checking. That's why PHP is a poor language to choose if you want to restrict your code, without using a third-party app there is pretty much nothing you can do to stop a reverse-engineer from tearing your code apart.

ShawnCplus 456 Code Monkey Team Colleague

To elaborate on my previous statement. It is not encoded, it is obfuscated. Though technically, since PHP is interpreted, there is no way to truly encrypt PHP without a third-party application. As an example, this is what that code looks like with normal variable names.

$var1 += (ord($var2[$var3]) >> 4);
if ($var1) { $var4 =
ShawnCplus 456 Code Monkey Team Colleague

It's not encoded. Obfuscation != Encryption. Please provide all of the PHP, not just 2 lines of it.

ShawnCplus 456 Code Monkey Team Colleague

Actually your "pure html" example looks almost identical to ColdFusion from Adobe or, similarly, Genshi in Python.

ShawnCplus 456 Code Monkey Team Colleague

Syntactically the shortest leap is Ruby, which was influenced by Python. PHP on the other hand has a stronger backing from Perl and C.

ShawnCplus 456 Code Monkey Team Colleague

If you already know python and want to learn a web language you might want to consider Django, a web framework in Python. Would be easier than learning a new language.

ShawnCplus 456 Code Monkey Team Colleague

I mean fix the string. You have a string that is essentially static, then you're doing a replace on it for no reason. Just manually replace wnav with bnav

ShawnCplus 456 Code Monkey Team Colleague

Do some debugging to make sure $_SERVER is the string you're looking for, if the string isn't being replaced correctly its most likely because you are searching for the wrong thing. As a side note, the replace is really, really unnecessary unless there is another reason for it. It would be faster just to fix the strings.

ShawnCplus 456 Code Monkey Team Colleague

Why are you doing a string replace after you create the string instead of actually modifying the original string, its wasted CPU cycles, even if it is minimal.

ShawnCplus 456 Code Monkey Team Colleague

I had this problem in Joomla! with my php code that I was including in an article through the plugin sourcerer. Well, needless to say, my web hosting changed to php 4 without me knowing why, I changed it to php 5 as the compiling engine and it worked like a charm.

I'm pretty sure you just bumped a thread that was over 2 years old, that has to fit into the Daniweb drinking game if it exists.

ShawnCplus 456 Code Monkey Team Colleague

Firstly, you have two functions that do exactly the same thing. Secondly, you're passing an array to a function file_get_contents that accepts a string.

<?php
$req_url = array('http://www.first.com', 'http://www.second.com', 'http://www.third.com');

function get_inner_string($a,$b,$c) // Gets a string between 2 strings
{
  $y = explode($b,$a);
  $x = explode($c,$y[1]);
  return $x[0];
} 

foreach($req_url as $url) {
  $page = file_get_contents($url);
  echo get_inner_string($page, '<head>','</head>');
  echo get_inner_string($page, '<body>','</body>');
}
?>
ShawnCplus 456 Code Monkey Team Colleague

Why are you a refugee from Apache? If anything it would be a refugee from IIS.

ShawnCplus 456 Code Monkey Team Colleague

=== is not a syntax error. It checks to make sure they are the same value and the same type.

$number = 1;
$string = "1";
if($number === $string) {
  echo "They match!"; // This won't happen
} else {
  echo "They don't match!"; // This will happen
}
ShawnCplus 456 Code Monkey Team Colleague

All of those str_replace 's are unnecessary. There is a built in PHP function.

$formatted_text = nl2br($text);
ShawnCplus 456 Code Monkey Team Colleague

Depends on what type of testing. In most cases testing should be done during development, not at the end.

ShawnCplus 456 Code Monkey Team Colleague

It is a pretty good start at OOP however I would suggest to you that as a general rule of thumb with OOP methods are named in CamelCase format ie.,

class someClass
{
  private $some_property;
  
  public function someMethod()
  {}
}

So properties(fields in Java) are written in underscore format some_property and methods are written in CamelCase public function someMethod...

ShawnCplus 456 Code Monkey Team Colleague

you can't link to the page to submit a form. The <a href="../elist.php"><button>Submit</button></a> should be

<input type="submit" value="Submit" />

Side note: There is absolutely no reason to use javascript to submit that form.

ShawnCplus 456 Code Monkey Team Colleague

So let me get this straight. You want to steal someone else's application so the same wont happen to you?
There are alternatives, like licensing. If someone violates your license sue them, although I don't promote being a litigious fanatic since no one needs more of them.

ShawnCplus 456 Code Monkey Team Colleague

oh, heh, you're giving mysql_num_rows the connection, you should be giving it the result.

mysql_num_rows($code)
ShawnCplus 456 Code Monkey Team Colleague

Your query is failing, use mysql_error to check it.

ShawnCplus 456 Code Monkey Team Colleague

What is the warning? Also, using error suppression is usually bad practice unless absolutely necessary. You should create cases if the variables don't exist so you can easily handle it either way.

ShawnCplus 456 Code Monkey Team Colleague

(([url]http://)?([/url][\w\-/\.]+)+\s) is a much simpler regular expression and does the same thing. Match 1 is your link so you can pretty much just replace your regex with that and replace \\0 with \\1.
However it can't really be fixed by a one-liner.

$link = preg_replace('#((http://)?([\w\-/\.]+)+\s)#', '\1', $r->text);
$link = (strpos($link, 'http://') === false)) ? $link = 'http://'.$link : $link;
$link = "<a href='$link' title='$link' rel='nofollow'>$link</a>';

That gives you the fully prepared link.

ShawnCplus 456 Code Monkey Team Colleague

He already solved it with adding the ; on the end inside quotes.

ShawnCplus 456 Code Monkey Team Colleague

If you're inside a PHP script you can open and close your PHP tags as much as you want. Anything not inside the tags will be rendered to the browser as text just as if it were in an HTML file.
The code <?php echo $xyzimage ?> in the CSS is what puts the background image in the CSS

ShawnCplus 456 Code Monkey Team Colleague

heh, the style tags can't show up in PHP code.
For future reference echoing out HTML in PHP can create some serious spaghetti code so you should avoid it if possible.
So instead of echoing you would close your PHP tag, then put in those style tags, then re-open your PHP tags

// some code
?>
<style type="text/css">
 ...
</style>
<?php
 // rest of your code