TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2008, 07:19 AM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 254
Thanks: 39
sarmenhb is on a distinguished road
Default help with code

im trying to use file() to grab the source code of a webpage and position the pointer to where the keywords are displayed and print them to the screen. but i keep getting errors, can you see why?

i thank thee from the deepest

Code:
<?php
if(isset($_POST['submit'])) { 

$code = $_POST['url'];
$source = file($code);

foreach ($source as $line_num => $output) {
//for each key as value  key is hidden , value is line number looking in $source
    
	$str = $output;
	$start = strpos($str, 'content=\"') + 1;
	$end = strpos($str, "\"");
	$keyword = substr($str,$start,$end, - $start);
	$keys = explode(",", $keyword);
	
}
	for($i=0;$i<count($keys); $i++) 
	{ echo $keys[$i]."<br/>";
}

else { 

?>
<html>
<head>
</head>
<body>
<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
url: <input type="text" name="url"/><br/>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
<? } ?>
Error: arse error: syntax error, unexpected T_ELSE in C:\wamp\www\test.php on line 21
__________________
http://www.sarmenhb.com
Send a message via AIM to sarmenhb Send a message via MSN to sarmenhb Send a message via Yahoo to sarmenhb Send a message via Skype™ to sarmenhb
sarmenhb is offline  
Reply With Quote
Old 02-04-2008, 08:51 AM   #2 (permalink)
The Acquainted
 
sjaq's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 104
Thanks: 9
sjaq is on a distinguished road
Default

Try indenting your code next time, its easier on the eyes
PHP Code:
<?php
    
if(isset($_POST['submit'])) { 

        
$code $_POST['url'];
        
$source file($code);

        foreach (
$source as $line_num => $output) {
        
//for each key as value  key is hidden , value is line number looking in $source
    
            
$str $output;
            
$start strpos($str'content=\"') + 1;
            
$end strpos($str"\"");
            
$keyword substr($str,$start,$end, - $start);
            
$keys explode(","$keyword);
    
        }
        
        for(
$i=0;$i<count($keys); $i++) { 
            echo 
$keys[$i]."<br/>";
        }

    } else { 

?>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
            url: <input type="text" name="url"/><br/>
            <input type="submit" name="submit" value="submit"/>
        </form>
    </body>
</html>
<? ?>
It looks like you forgot to close the for loop:
PHP Code:
for($i=0;$i<count($keys); $i++) 
    { echo 
$keys[$i]."<br/>"
b.t.w. I hope you know this script is really insecure at the moment, you're including a file that the user can specify without cleaning up the input, so someone could just put in /etc/passwd in the POST field and get that file. I always use str_replace to remove every / from the given string.
sjaq is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 05:26 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0