Jump to content

FunkyELF

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

FunkyELF's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [quote author=printf link=topic=111702.msg452829#msg452829 date=1161034405] Also [b]glob()[/b], would be much better than scandir() and that foreach() your using to build the jpg array! [code]$dirname = './images/'; $pictures = glob ( $dirname . '*.jpg' );[/code] [/quote] Does glob only work on the current directory?
  2. [quote author=printf link=topic=111702.msg452829#msg452829 date=1161034405] if get $_GET['size'] is a [b]integer[/b], then... [code]$size = intval ( $_GET['size'] );[/code] Also [b]glob()[/b], would be much better than scandir() and that foreach() your using to build the jpg array! [code]$dirname = './images/'; $pictures = glob ( $dirname . '*.jpg' );[/code] me! [/quote] Thanks, the fact that size should only be an int never occured to me. As far as that glob goes, I don't think my book went into it.  Its things like that where I'll just wind up reinventing the wheel. Anyway, how about that cat command?...is that the right way to go about things using passthru?
  3. I thought of an exercize for me to put some of my newly learned PHP to use. I post on a couple of different forums and some allow for offsite avatars.  I thought I could create a PHP script to serve up a random avatar. I think I got it working although I haven't tried it on any forums yet. I was hopeing someone could look at this and critisize it. What is the best way to just serve a file from PHP using passthru. All the examples I saw were with programs that were converting things or resizing them but none just giving the image as is. I figured I could use the cat command and it works but is there a better way than this?... [code]passthru("cat " . $file );[/code] Thanks, ~Eric I know I'm not sanitizing the $_GET['size'] variable and its going right into a command string...what is the best function to sanitize something like this? [code]<?php     $dirname = dirname($_SERVER['SCRIPT_FILENAME']);         // get the files in the same dir as this script.     $files = scandir($dirname);         // filter for only .jpg files     foreach($files as $file){         if(substr($file,-4) == ".jpg")             $pictures[] = $file;     }         // pick the random file     $rfile = $pictures[mt_rand(0,count($pictures) - 1)];         header("Content-type: image/jpeg");         // resize if we need to     if(isset($_GET['size']))         passthru("convert -resize {$_GET['size']}x{$_GET['size']} $rfile jpg:-");     else         passthru("cat " . $rfile ); ?> [/code]
  4. [quote author=lead2gold link=topic=111438.msg451650#msg451650 date=1160770790] i modified your code to do what you ask... :) try it out [/quote] Thanks, I figured it was probably something easy.  I was looking at html forms on w3schools but it didn't mention that where I was looking. I just bought a book on PHP and MySQL and I'm trying to learn it but it looks like I also need to pick up a book on HTML, CSS, Java script, XML. A book that would teach all of that would no doubt be bloated and not go into enough detail to be useful but it really seems like a pain to become an expert in all of those things to make a decent web page. In C, you learn C and you can make a decent program. In Java, you learn Java and you can make a decent program. To make a decent web page the right way with PHP, you need to learn at the very least HTML and CSS and to make it functional you'll need to additionally learn MySQL and Java Script.  >:( >:( >:(
  5. Hey guys, As an excersize, and to take a break from my book, I tried putting together the following page.  It has a hard coded secret number and you have to guess what it is.  It tells you whether you need to guess higher or lower.  It works okay.  I am wondering what a good way to have a counter would be.  To count the number of guesses. Right now it counts the guesses but it does so using a visible field which can be edited.  Is there a way to pass information using post without it being visible like it is now? Thanks, ~Eric [code]<?php     $tries = 0;     if(isset($_POST['okay'])){         $tries = $_POST['tries'] + 1;         $secret = 27;         if($_POST['guess'] < $secret){             echo "higher<br/>";         } else if($_POST['guess'] > $secret){             echo "lower<br/>";         } else {             echo "hooray ... got it in " . $tries . " tries<br/>";         }             } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">     <input type="text" name="guess" value="<?php echo @$_POST['guess']; ?>">Guess<br/>     <input type="text" name="tries" value="<?php echo $tries; ?>">Tries<br/>     <input type="submit" name="okay" value="SUBMIT ! ! !"><br/> </form>[/code]
  6. [quote author=btherl link=topic=111338.msg451249#msg451249 date=1160720925] http://sg.php.net/manual/en/function.htmlspecialchars.php will probably do it.[/quote] Nope.  Did you try it? Besides still placing the buttons there and allowing anything I want to get rendered by the browser, the stuff that actually stayed in the orange box wasn't highlighted at all !
  7. Hi guys, this is my first post on here so don't hate on me. I'm brand new to PHP and the only HTML I have done was static stuff 7 or 8 years ago. With that being said...I came across a site showing how to highlight PHP using PHP.  What I really want is for any request for a .phps file (which doesn't exist) to pass the coresponding .php file though the highlighter...but I'll save that for another post. What I came across was the following code which I put in my htdocs directory.... highlight.php: [code]<?php if (!empty($_POST['text'])){     echo '<div style="border: solid 1px orange; padding: 20px; margin: 20px">';   highlight_string($_POST['text']);   echo '</div>'; } ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">   <textarea name="text" style="width: 100%; height: 500px"><?php        echo @$_POST['text'];    ?></textarea>   <br />   <input type="submit" value="Highlight" /> </form>[/code] So I try it out and it works pretty well.  Then I decide to have it parse itself and I copy the entire file into the field and press "highlight" and what I get at the bottom was two "highlight" buttons. Now, if I go and paste the following in there, I get 4 buttons saying "Should" "These" "Be" and "Here?" above the "highlight" button. [code]<?php if (!empty($_POST['text'])){     echo '<div style="border: solid 1px orange; padding: 20px; margin: 20px">';   highlight_string($_POST['text']);   echo '</div>'; } ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">   <textarea name="text" style="width: 100%; height: 500px"><?php        echo @$_POST['text'];    ?></textarea>   <br />   <input type="submit" value="Should" />   <input type="submit" value="these" />   <input type="submit" value="be" />   <input type="submit" value="here?" /> </form>[/code] Its not that it contains non PHP stuff is it?...If I paste the following it works fine and I see <H1>Where am I?</H1> inside the orage rectangle where it should be but if I put <H1>Where am I?</H1> under those <input> buttons in the above example, the text "Where am I?" gets rendered as a heading. [code]<?php     echo "Will the following be inside or outside the orage box?<br/>"; ?> <H1>Where am I?</H1>[/code] Somewhere in there it seems like it is getting out of the highlight_string function and the remainder gets dumped and rendered by the browser.  Is this bad for security since anything could get displayed by the browser?  What is the worst thing that could happen?... a javascript redirect?  Obviously if you're reading this, whoever wrote this forum software did their syntax highlighting the right way otherwise you'd be seeing my input buttons on this page. Thanks in advance, ~Eric
×
×
  • Create New...

Important Information

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.