daynah

  • Jan 16, 2023
  • Joined Mar 15, 2001
  • Hello NotVeryTechie, a very simple way of doing this is by using this logic.

    Create an array of questions (below I used 3 questions), and select a random id from the array using rand(), and then print out the value.

    $QuestionArray = new array(3);
    $QuestionArray[0] = 'Question 1?';
    $QuestionArray[1] = 'Question 2?';
    $QuestionArray[2] = 'Question 3?';
    
    $myRandomNumber = rand(0, 2);
    
    echo $QuestionArray[$myRandomNumber];
    

    I hope this helps!

    • Originally posted by ShawnK
      http://www.php.net/

      RTFM!

      That's not a helpful post either.

      kripz, I strongly suggest you NOT validate username and passwords through URL's. Instead, pass them through a form and in your auth script, check with your database if the username and passwords match.

      In your database, have a query similar to:

      SELECT username, password FROM userpass WHERE username='$username' AND password='$password'

      If there are results, then the user is a valid user. Of course, you might want to do more robust checks, but that would be one simple way of doing it.

      If you really want to have a url the validates a user, I suggest you send a random key instead of clear text username and password.

      • Well, hello there, and welcome to the board. 🙂

        • You can try including files using their absolute paths. Something similar to:

          <? include('/www/htdocs/oscommerce/includes/application_top.php'); ?>
          
          • You should be using both mysql and php to check this.

            mysql would hold the data, and php would be used to write the script.

            You can have a tinyint field for 'car_availability.' And if it's 1, that means it's available, if it's 0, then it's not. Then on a page that displays all available cars, run a query like:

            $query = "SELECT * FROM cars WHERE car_availability='1'"

            Of course, you could would be more complex, but this is only a simple example.

            • $_REQUEST['variable'] - Variables provided to the script via any user input mechanism (GET, POST, COOKIE) and which therefore cannot be trusted.

              If you use $POST or $GET (for forms of course), you know that those variables were the user's inputs from a forum, and not a hacked url.

              • I wrote a quick function for you. But of course, you'll need to tweak this code a bit to make it more robust. For example, you might want to limit only 28 or 29 days for the month of Feburary. Maybe convert the month names back into numbers for more flexibility too. 🙂 Good luck!

                Demo Example

                Full Code (if it's too hard to read on the board)

                <?
                
                function selectCurrentDate($currentMonth, $currentDay)
                {
                	// Month Array
                	$monthNames = array('January', 'Feburary', 'March', 'April', 'May', 'June', 
                			  'July', 'August', 'September', 'October', 'November', 'December');
                
                // MaxNumber of days in a month (will need to write more robust code)
                $maxDays = 31;
                
                // Begin Month select menu
                $display .= 'Select The Date: <select name="theMonth">';
                
                // Loop through each month
                foreach ($monthNames as $myMonth) 
                {
                	// If month is equal to $currentMonth passed in, select 
                	if($currentMonth == $myMonth)
                		$display .= '<option value="'. $myMonth .'" selected>' . $myMonth . '</option>';
                	else
                		$display .= '<option value="'. $myMonth .'">' . $myMonth . '</option>';
                }
                
                // end select	
                $display .= '</select> ';
                
                // Begin Day select Menu
                $display .= ' <select name="theDay">';
                
                // Loop through the max number of days
                for($i = 1; $i < $maxDays; $i++)
                {
                	if($i == $currentDay)
                		$display .= '<option value="'. $i .'" selected>'. $i.'</option>';
                	else
                		$display .= '<option value="'. $i .'">'. $i.'</option>';
                }
                
                $display .= '</select><br /><br />';
                
                return $display;
                }
                
                // Test out the function
                echo selectCurrentDate('March', 5);
                echo selectCurrentDate('Feburary', 28);
                
                ?>
                • Sure you can.

                  First, start by making a base layout in one page. Then separate it into a header.php and a footer.php

                  Then for your pages, just add the content but include the headers and footers.

                  Example: Create an aboutme.php page.

                  <? include('header.php'); ?>
                  
                  my about me content goes here. my about me content goes here. my about me content goes here. my about me content goes here. my about me content goes here. my about me content goes here. 
                  
                  <?php include('footer.php'); ?>
                  
                  

                  Include files really help separate the content from the layout format. 🙂

                  • In this line,

                    print "<option" . $sectionNameSelected[$g] . ">" . $g . "</option>\n"; 

                    Where is the value attribute?

                    • I'm not sure if this will help, but try changing:

                      $result = mysql_db_query($db, $query, $connection) or die("Error in query."

                      to

                      $result = mysql_db_query($db, $query) or die("Error in query."

                      • What kind of editor are you using now? Is it web-based? Are you looking for a web-based one? Please be more specific. 🙂

                        • I usually write them in classes and then include those files when I need them. Splitting them up into files/classes is easier to comprehend, especially when I don't look at the code for months.

                          • heh, changed it. People I know offline actually use either one. 🙂

                            • So.... do you have plans for Valentine's day? Let's hear about it. 🙂

                              It's Feb. 14th in case you didn't know... heh

                              • Why didn't I write this up earlier?! Anyhow, better late than never right? 🙂

                                Photos: points to the left See avatar. 🙂
                                Name: Dana
                                Age: 25
                                Kids names/ages: No kids yet.
                                Pets types/names: Hopefully getting a puppy soon, once we buy a house.
                                Meaning behind your username: Just my name, but spelled differently.
                                Most valued possession: My Knowledge! Is that saying much? =P
                                Fav type of music: Pop, love songs, 80's, dance music
                                Favorite movies: Finding Nemo, Toy Story, Monster Inc, Ice Age, Lord of the Rings, Harry Potter, Pirates of the Carribean
                                Favorite computer game: Bricks? lol I like Dynomite too. Not really into RP games.
                                Favorite computer program: Adobe Photoshop!
                                Type of car you drive: 2003 VW Passat
                                Type of car you really drive (the truth please): I wasn't lying the first time you asked that!
                                Fav alcoholic beverage: I don't drink.

                                Next vacation: Probably to Las Vegas with my family one of these days.
                                Unique talent: I have one? heh
                                Most embarrassing moment: Too many to name? I trip and fall a lot. =P

                                Background: I was born in CA, USA. My interest in computers started in the middle of High school when the Internet was really new. I decided to pick Computer Science as my major when I reached the Univ. and at the time, that major was new as well. As the years went on, my new found passion was creating webpages every chance I had. I graduated from the Univ. in 2000 with a CS degree. And before long, I picked up PHP and mysql because I needed to automate a lot of my content. And here I am today... doing the same stuff, for a living (just not on my own domain. heh)
                                Focus of work: Mostly creating web applications that help automate library functions.
                                Which platform do you use: Windows 2000
                                Fav PHP editor/IDE: Macromedia Homesite
                                What's your favorite PHP function/why? explode() - the name itself sounds fun. 😉
                                Tips for the noob: Start out with small projects and practice with simple functions before jumping into any large projects. 🙂 Reading the manual and tutorials always help too.

                                Why do you volunteer your time as a moderator? I really enjoy helping people as well as learning new things from them.

                                Free for all (anything you'd like to say): My other hobbies include photography and scrapbooking. They do sorta go hand-in-hand huh? I also enjoy doing artwork but haven't had much time to work on that.

                                If there's anything you'd like to ask... ask away. 😃

                                • It really depends on how popular the forum is. A board like this could probably take up 10 megs - 20 megs of data in the mysql database. The scripts for the board itself is probably less than 2 megs of files. 😉

                                  • This was a fun problem to solve. 🙂

                                    I googled and found this wonderful link: http://www.desilva.biz/php/xtracturl.html

                                    It gives you the URL pattern to use. Then I used the function preg_match() to find the URL in a string.

                                    Then I wrote some sample code that may help you:

                                    <?php
                                    
                                    $myText = 'I love to surf on [url]http://phpbuilder.com[/url]';
                                    
                                      $urlpattern = '/((http|https|ftp):\/\/|www)' // line 1
                                        .'[a-z0-9\-\._]+\/?[a-z0-9_\.\-\?\+\/~=&#;,]*' // line 2
                                        .'[a-z0-9\/]{1}/si'; // line 3
                                    
                                        $match = preg_match($urlpattern, $myText, $matches);
                                    
                                        if($match)
                                        {
                                            echo 'The original string is:<br />' 
                                    . $myText . '<br /><br />';
                                                echo 'The URL in the string is:<br />' 
                                    . $matches[0] . '<br /><br />';
                                    
                                            $newText = eregi_replace ($matches[0], '<a href="' . $matches[0] . '">' . $matches[0] .
                                    '</a>', $myText);
                                    
                                                echo 'The new string is:<br />' . $newText
                                     . '<br /><br />';
                                            }
                                            else
                                            {
                                                    echo 'There are no URLs in the String.';
                                            }
                                    ?>
                                    

                                    the variable $urlpattern is explained in the link above.

                                    $myText = 'I love to surf on http://phpbuilder.com';
                                    This is the string I used. You can replace this with your textarea content.

                                    $match = preg_match($urlpattern, $myText, $matches);
                                    This return 1 if there is a matching pattern in the string.

                                    $matches is an array that returns the string that matches. $match[0] returns the full URL.

                                    If you have any other questions on the script, just leave a post. 🙂 It should get you started on your script.

                                    • WaQuEe, you may advertise your link in your signature, but creating a thread solely to advertise your site is not allowed. Hope you understand, thanks,

                                      -Daynah

                                      • What is that? "Blog system"?

                                        A blog system is a tool that helps you update a journal or 'weblog' easily. 🙂

                                        http://cafepress.com
                                        - http://wordpress.org
                                        - http://b2evolution.net

                                        http://pmachine.com
                                        http://moveabletype.org
                                        http://www.noahgrey.com/greysoft/ (perl)

                                        Hosted:
                                        http://blogger.com
                                        http://livejournal.com - open source
                                        http://blurty.com
                                        http://ujournal.com
                                        http://www.deadjournal.com
                                        http://radio.userland.com/
                                        http://www.xanga.com

                                        And LOADS of other blogging tools can be found here:

                                        http://www.lights.com/weblogs/tools.html

                                        But what do I recommend? b2 (cafelog) or one of the variations of it. 🙂

                                        And if you don't want to host it yourself, I'd go with livejournal or xanga. The community there are great as well. 😉