Help me to sort out this

Discussion in 'Programming' started by Freewebspace, Dec 2, 2006.

  1. #1
    I want help from you

    this is the question

    If you type "freewebspace" in a search box and click on a button The browser should display the "freewebspace.html" within the same directory
     
    Freewebspace, Dec 2, 2006 IP
  2. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #2
    This will do what you want:
    
    <?php
    
    if (isset($_POST["submit"]))
    		{
    		if ($_POST["filename"] == "")
    				{
    				echo "Please enter a file name";
    				}
    				
    		else	
    				{
    header('Location:' . $_POST["filename"] . ".html");
    				}
    
    		}
    		
    else
    		{
    		echo	"<form action=\"". $_SERVER['PHP_SELF'] ."\" method=\"post\" enctype=\"multipart/form-data\">
    				<input name=\"filename\" type=\"text\" />
    				<input name=\"submit\" type=\"submit\" />
    				</form>";
    		}
    
    ?>
    Code (markup):
    Let me know if you have any problems.
     
    papa_face, Dec 2, 2006 IP
    Freewebspace likes this.
  3. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #3
    Thank you I will try out it

    Excellent !

    I will contact you for some surprise gift to you

    If you have a website PM me I will add your site as a Featured links in my directory
     
    Freewebspace, Dec 2, 2006 IP
  4. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #4
    No problem :)
    Website address PM'ed.
    P.S Oh by the way I added a little extra to the code above. Not sure if you got it or not, so amend the file to the above code :)
     
    papa_face, Dec 2, 2006 IP
  5. Luke

    Luke Peon

    Messages:
    111
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I don't know if this is a problem, but since POST is provided by the user, would you benefit from a tiny bit of moderation on your post vars?

    I cant think of anyway to exploit that code currently but you are including with no moderation at all. if the user used a ' or " or . it may break the script, not sure.

    Hope it all works out for ya.
     
    Luke, Dec 4, 2006 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    Luke is right ;

    header('Location:' . $_POST["filename"] . ".html");

    should be

    header('Location:' . stripslashes(trim($_POST["filename"] )) . ".html");
     
    krakjoe, Dec 4, 2006 IP
  7. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #7
    It worked very well for me

    Thank you all of you
     
    Freewebspace, Dec 7, 2006 IP
  8. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #8
    sorry for bumping this

    If the file suppose does not exist I want to go to it the main page

    what should i do?
     
    Freewebspace, Dec 19, 2006 IP
  9. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #9
    Arghh, mod please delete this, I got all confused....
     
    krakjoe, Dec 19, 2006 IP
  10. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #10
    
    <?php
    
    if (isset($_POST["submit"]))
    		{
    			if ($_POST["filename"] == "")
    			{
    				echo "Please enter a file name";
    			}	
    			elseif(!file_exists(stripslashes(trim($_POST['filename'] )). ".html"))
    			{
    				header("location: mainpage.php");
    				exit;
    			}
    			else
    			{
    				header('Location:' . stripslashes(trim($_POST["filename"] )) . ".html");
    				exit;
    			}
    		}
    		else
    		{
    			echo	"<form action=\"". $_SERVER['PHP_SELF'] ."\" method=\"post\" enctype=\"multipart/form-data\">
    					<input name=\"filename\" type=\"text\" />
    					<input name=\"submit\" type=\"submit\" />
    					</form>";
    		}
    
    ?>
    
    PHP:
     
    krakjoe, Dec 19, 2006 IP
  11. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #11
    Thank you Krakjoe!

    I will contact you if I have any further problems
     
    Freewebspace, Dec 19, 2006 IP