Jump to content

ThePsion5

Members
  • Posts

    203
  • Joined

  • Last visited

Everything posted by ThePsion5

  1. Header and cookie information have to be set before any output occurs. And see that extra line up at the top? That's output, lol.I only know this from making the same mistake many times. Also, I would advise that you use <?PHP instead of <?, as the latter can also signify XML code.Another thing is that you may not be able to set cookie information in an included file if there is output before that file is included...same deal with there being output to the browser before the header information is set. You'll probably have to deal with cookies in your primary page instead of the included one.
  2. I'm very much tempted to agree. Even if you encrypt the password before placing it into the javascript file, they already have the encrypted version that they can just supply to your verification page! Also, since the user can disable javascript, using it as the sole method of logging in is a bad plan because when javascript is disabled one of two things will happen: either the user will not be able to log in no matter what, or the user will always be able to log in - probably the latter. Why not use server-side validation?
  3. Well, I believe what you need at this point is something PHP can use to interact with a mail server...I've never had to do anything like that but i'd check out the list of PEAR extensions to PHP here, and possibly check sourceforge. Sorry I can't be of more assistance.
  4. I'm not entirely sure, but I think you can use break; to exit from the loop, but continue execution. If that doesn't work, you can recode your loop like so: $continue = true;while($e = mysql_fetch_array($results) && $continue){ if ($newalbum <= 5) { echo $e[album_title]."<br />"; $newalbum=$newalbum+1; if ($newalbum == "6") $continue = false; }} That will have the same effect as using break; in place of the $continue=false; line.
  5. You could also compress that into a single function, right? Like so: function toggleVisibility(){ var table = document.getElementByID('default'); if(table.style.display == 'block') table.style.display == 'none') else table.style.display == 'block';}
  6. Cool, that works pretty well. Could I also do the same thing given only the ID of the form element? I think i'd have to do something like this:function alertAndFocus(formName, fieldName, alertMessage){ var thisForm = document.forms[formName]; var labels = thisForm.getElementByTagName("label"); for(var i=0; i < labels.length; i++) { var field = document.getElementByID(fieldName[i].for); var label = field.value; alert(alertMessage . label); }} Then call the function like so: alertAndFocus('someForm', 'requiredField', 'Please Enter a value for:') To create an alertbox that says this: Is this correct? Sorry to be a pain, but i'm not as experienced with JavaScript as i'd like to be. Thanks!
  7. Hi, I'm writing a piece of javascript code that validates a form field by using an alert box. I want this code to by dynamic, so instead of writing the individual messages myself I want to use the label field in the message. FOr example, here's the HTML: <label for ='email'>E-Mail Address</label><textarea name='email' id='email' /> And here's what I want the alert field to say: Shouldn't I be able to use DOM to do this? I think so, but i'm not sure and i'm not exactly sure how to go about this. Ideally, I could specify what field i'd be looking for as a function paramater. Any assistance?
  8. To turn multiple spaces into one space, you'll need a regular expression like this: $RegExp = '%[\s]{2,}%';$Text = preg_replace($RegExp, ' ', $Unfiltered); Hope it helps EDIT: Oh, i missunderstood what you wanted to do. Instead of using a regular expression, this should work just as well: $Text = str_replace(' ', '', $Text) That will give you what you need, and it's plenty faster than regular expressions too.
  9. This tutorial is alright, but it actually contains some significant flaws that we should be aware of:1. Using global variables - They prevent direct access to their pages by checking variables like so: if($first_name != true && $email != 'yourEmail@somewhere.com'){print 'Not authorized, n00b!';} Unfortunately, all I have to do is know your e-mail and i can access it anyway by typing: And now I have access to all your stuff! Hope you didn't post your e-mail anywhere on the site, lol. I'll have to go through the rest and find anything else that's dangerous...
  10. Your problem appears to be that you're trying to set the values of the $_GET field - since GET is stored in the URL, there's not really a good reason to set it since by the time that happens the URL has already been sent to the browser. You should probably use POST instead anyway, because GET will allow anyone to put their own values in if they know how.In case i'm wrong, insert some echo statements into the $error == 0 code block and see if they're ever reached.
  11. Ok, so you want to get the number of topics, but you only have a table holding forum posts with topics as VARCHAR() fields, I'm guessing. You can do that without much of a problem, actually. Just do this: SELECT DISTINCT post_name FROM post_table; Hope this helps
  12. Actually, I found an interesting way to record error information without using any of those (i'm not in a position to install PEAR/PECL extensions on this server). It's suprisingly easy: @ob_flush();@ob_start();fopen(this/file/not/there.html, 'r');$Text = ob_get_contents();/*Warning: fopen(this/file/not/there.html): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found.*/ob_end_clean();//use a regular expression to parse the error informationreturn $Parsed; //Something like "HTTP/1.0 404 Not Found"
  13. Actually, I've experimented with using PHP to write dynamic javascript form-validation code, it would work something like this:The page with the form includes the following line function produceValidationScript($FormName, $Required=array(), $Email=array() $ScriptName='validate'){ $Code = "function validate(thisForm)" $Code .= 'var valid = true'; $firstLine = true; foreach($Required as $Field) { if($firstLine) $firstLine = false; else $Code .= 'else '; $Code .= 'if(!(' . getNonBlankJS($Field) . '))'; $Code .= getAlertAndFocusJS($Field, 'Please specify a value for ' . $Field); $Code .= '{ valid = false; }''; } foreach($Email as $SingleEmail) { if($firstLine) $firstLine = false; else $Code .= 'else '; $Code .= 'if(!(' . getValidEmailJS($Email) . ')); $Code .= getAlertAndFocusJS($Field, 'Please specify an appropriate e-mail address'); $Code .= '{ valid = false; }'; } $Code .= 'return valid;\r\n';}function getNonBlankJS($ElementID){//Return javascript code that returns whether an element is blank or not}function getAlertAndFocusJS($ElementID, $Message){//Return javascript alert code that focuses on the item in question and alerts the message}function getValidEmailJS($ElementID){//Return javascript code that returns whether an e-mail is valid or not} And then you could just call the function in the validation.php file like this: print validate(explode($_GET['form'], explode(',', $_GET['required']), explode(',', $_GET['email')); Granted, this seems like almost as much a pain as just writing the JS yourself, but if you have a website dealing with alot of forms it might bre pretty useful.You could also make this code more efficient by including the javascript code snippets in a separate file with a instead of producing them on the fly every time, for one thing.
  14. Hi,I'm trying to create a PHP script that basically tests for broken/inaccessable links. Is isn't enough, however to just know that they can't be accessed, which one can find out easily just by attempting to open a file with file_get_contents(). Is there anyway to retrieve the HTTP error code when a PHP function fails to open a remote file (without installing PEAR/PECL extensions)?
  15. Yeah, I was hoping that i'd be able to avoid putting the function in an object and then extending it, but that seems like the best way to get the job done in this case, lol. Thanks!
  16. Hi,Not too long ago I had created a large set of php objects that performed several tasks together. Several functions were common to otherwise unrelated objects, so I created a few global functions to simplify development, like so: function _parseURL($URL){//do various things here} Now I'm extending one of these classes, but I need to alter the previous function a little in order to do what I need to do. Simply replacing the function calls in the extending class isn't a very good solution as this basically forces me to rewrite most of my original class, which i'm hoping to avoid, which leads me to my actual question: can I override the original function in a different file? In an ideal world, i would love to be able to do this: require_once('Crawler.class.php') //Contains the class I'm extending and the function in questionclass ErrorCrawler extends Crawler{//some additional code}function _parseURL($URL){//does a few things differently here} I know that this probably isn't possible, but it would be so very convenient if it was. Any idea?
  17. Why can't we all just use Firefox?
  18. Unfortunately, I'm doing this for my myspace profile. And while trying to add custom CSS to myspace is like dressing up a dead horse, I figure that it should look fairly nice as to improve my standing as a web designer, and as a personal challenge too, lol. You can find it here - The backgrounds look fine in FF but break completely in IE...unfortunately, so does the primary source of my inspiration for this design. If you can get it to work, however, then that gives me hope.
  19. Ok, so i'm trying to create that semi-transparent feel for my website using two fixed background images, the second of which is whitewashed to look create the translucency effect. Here's the CSS for the two: body{background: black url("http://home.gwu.edu/~sean_m/images/hosted/blueapophysis.jpg") no-repeat fixed top center;font-family: Arial, Helvetica, sans-serif;background-color: rgb(0, 0, 0);}div, table{background: black url("background-light") fixed no-repeat top center;background-color: rgb(52,52,52);} This works like a charm in firefox, but in IE the backgrounds scroll with the page and are not aligned properly, just the default top-left. Is there anything I can do about this, or am I stuck catering to IE's lack of proper CSS support?
  20. That's fairly helpful, if I do say so myself. Another important consideration when using sessions via cookies or URL passing is that for tabbed-based browsers, using cookies can present some confusion if there are different sessions taking place in different tabs. Whether this is a site design issue, browser issue, or just an issue of the general technology i'm not sure of, just an observation i've made.
  21. ThePsion5

    captcha test

    If you're willing to build your own version, I think that you could actually do it fairly easily by using PHP's Image functions...just create a random string of text, output it as an image, and then ask them what the string is.
  22. Hi guys, I'm testing out a crawler class that I wrote recently, and it's doing some strange things when I try to run it. A single file holds it and the related classes - It compiles correctly. However, when I add a test to the end like this: print 'Starting...<br />'; $Test = new Crawler('www.google.com'); $Test->crawlSite(); print 'Ending...<br />'; Firefox tells me that the document contains no data...a.k.a. a blank screen. If i comment out the two lines where I declare and then run the crawler, then it mysteriously works fine. What exactly is happening here?EDIT: I fixed it now....for whatever reason I managed to send it into an infinite loop but it wasn't outputting each iteration, lol.
  23. It seems like there could be an easy way around this, however. To make sure the exploit can't be used against you, simply do this: function dl_safe($extension){ $set = false; if(ini_set('enable_dl', true)) { $set = dl($extension); ini_set('enable_dl', false); } return $set;} This way, there's no window for the attacker to use dl() against the server since it's only turned on long enough for the extension to be loaded.
  24. Hi guys,At the moment I'm working on a computer to which I don't have administrative priviledges, which presents quite a few annoyances - the largest of which being that I can't restart the Apache server on it without restarting my computer, so this got me to wondering something. When using a server that you can't directly alter the configuration for (a web host, for example) and want to modify the PHP settings of said server to load additional modules (mySQL, GD, whatever else), I want to know if there's some way to load one of PHP's libraries dynamically. For example, if I write a script that uses the GD library on a server where PHP is not configured to run GD, could I somehow load it at script execution time? Perhaps using a statement similar to require_once(convoluted/path/to/gd.php) or something similar?
×
×
  • Create New...