Jul 26, 2008

Reading Site's Source Code With Php - is this possible?

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Reading Site's Source Code With Php - is this possible?

snlildude87
Hey guys. I want to know if it's possible to read a site's source code using PHP. Would using $blah = file(http://google.com); work?

I want to make a script that will retrieve the comic of the day from http://comics.com/. Currently, I have another source, http://ucomics.com/, but that site doesn't have some of the ones that I want. The thing is, http://ucomics.com/ uses an easy file name for each comic in their comic of the day. Here's an example of the file name: ga050826.gif. That is for August 26th, 2005. Simple stuff. http://comics.com/, however, uses an obscure file name: barkeaterlake2005018313826.jpg, and that changes everyday, so it's hard to find a pattern. Check their sites out if you want to see what I mean.

If you have another suggestion besides getting the source code, post it below.

Thanks!

 

 

 


Reply

littleweseth
QUOTE(snlildude87 @ Aug 27 2005, 04:00 AM)
Hey guys. I want to know if it's possible to read a site's source code using PHP. Would using $blah = file(http://google.com); work?

I want to make a script that will retrieve the comic of the day from http://comics.com/. Currently, I have another source, http://ucomics.com/, but that site doesn't have some of the ones that I want. The thing is, http://ucomics.com/ uses an easy file name for each comic in their comic of the day. Here's an example of the file name: ga050826.gif. That is for August 26th, 2005. Simple stuff. http://comics.com/, however, uses an obscure file name: barkeaterlake2005018313826.jpg, and that changes everyday, so it's hard to find a pattern. Check their sites out if you want to see what I mean.

If you have another suggestion besides getting the source code, post it below.

Thanks!
*



maybe you can try reading the sourcecode, then doing a regexp something along the lines of :
[CODE]preg_match ( '/src="[hH][tT][tT][pP]:////.+?/.(jpg|gif)"/', $big_string_with_sourcecode_in_it, $results_array), which should put any URI's that reference either .jpg's or gif's into the $results_array. From there on, you can roll your own code to pull each url from the array, filter out the ones you're not interested in (like the ads, layout graphics, and so on) and download the rest - maybe call wget from PHP?

If you don't know how regexps work or what they are, try reading www.huzilla.org/phpbook. In fact, read the whole thing - it's sure better than my paper hardcopy book, and it's free.

 

 

 


Reply

arboc7
I don't fully understand your question. If you are trying to read the PHP source of a file on another server, that is impossible as far as I know. If you are just trying to get the HTML source, you can use the Filesystem functions in PHP (http://us3.php.net/manual/en/ref.filesystem.phphttp://us3.php.net/manual/en/ref.filesystem.php).

Let me know if this helps and if you still need help getting the Filesystem functions to work.

Reply

Saint_Michael
i remember seeing a scripted called "abc news" where the person after putting the source code on his website would be filtered news updates from the abc site, i think using hte same script would be the most helpful to.

Reply

mike_savoie
There's a great php class called snoopy from sourceforge. Find it here: http://sourceforge.net/projects/snoopy/
Here's an example of how to use it.

<?php
$snoopy = new Snoopy;

$snoopy->submit($submit_url,$submit_vars);

$snoopy->fetch("http://www.google.com";);

print $snoopy->results;

?>

Reply

Spectre
The file() function is capable of retrieving HTML documents, as are the file_get_contents(), include(), require(), and readfile() functions (although without a bit of tweaking, the last three automatically pass the retrieved data to the output buffer).

file() returns an array, whereas file_get_contents() returns a single string - so file_get_contents() is more or less the equivalent of:
CODE
$html = file('document_path');
$html = implode("\n",$html);


If you are wanting to examine the source code, it would probably be better to have a single string value rather than an array.

littleweseth, whilst regular expressions are a good idea, your expression will not work - the image is stored locally, and is only referenced to in a relative manner. I would recommend narrowing it down to images that exist within the '/comics/' directory - I don't know if all 'comic of the day' images are stored there, but a quick look at the site shows that is where the current image is located, and it is the only image displayed on that page located in that directory. If that is the case, try this:

CODE
$html = @file_get_contents('http://comics.com/');
$pattern = '[<(img|IMG).*?(src|SRC)=\"/comics/(.*?).(jpg|JPG|gif|GIF|png|PNG)]';
preg_match($pattern,$html,$matches);
$image_path = 'http://comics.com/comics/'.$matches[3].'.'.$matches[4];
$image = file_get_contents($image_path);


Keep in mind that it may not be legal for you to leech content from that site. I would recommend you check first.

Reply

littleweseth
my bad - i just hacked out a regexp to look for image urls, without actually going to look at the site source. *blush*

btw, instead of using the alternation operator, a quicker and more elegant way of doing (PNG|png|JPG|jpg..) would be to just use the case-insensitive modifier, 'i'.

CODE

$html = @file_get_contents('http://comics.com/');
$pattern = '/<(img).*?(src|SRC)=\"\/comics\/(.*?).(jpg|gif|png)/i';
preg_match($pattern,$html,$matches);
$image_path = 'http://comics.com/comics/'.$matches[3].'.'.$matches[4];
$image = file_get_contents($image_path);



By the way, i think you need to escape the backslashes, but i'm not sure. Also, don't you need /'s at the beginning and end of the pattern?

Reply

Spectre
No, you don't need /s. You can use pattern modifiers if you wish, but only if you require certain operators to act in a slightly different way.

The /i option may work, but it is most likely slower - it will treat the whole pattern as case insensitive, and matching any combination of upper and lower case characters to form a word which is much more resource intensive than binary/explicit matching.

You do need to escape backslashes - but not forward slashes. Backslashes only need to be escaped because they themselves are used for 'escaping' characters.

I made a mistake in my pattern. It should be:
CODE
..."/comics/(.*?)\.(jpg|...

Instead of what it currently is ('.', a single dot, matches almost any character - with the exception of linebreaks, UNLESS /s is used - and the character we are trying to match here is just a normal period/fullstop/dot).

Reply

littleweseth
*thwack*

Me needs to go back to regexp school - and possibly get a PHP book that doesn't suxor (i was looking at PHP in 24 Hours (SAMS publishing) because i couldn't be bothered opening my local copy of hudzilla when i had a hardcopy book just sitting there. In that book, they always use /'s.)

[As a matter of curiosity, I didn't learn PCRE's by looking at the Perl docs, or the PHP docs, or even any websites - I learned from the manual of BBEdit, that beacon of Mac l33tness. It covers pretty much everything, right down to conditionals and lookaheads, so I tend to think in terms of those. I find it impossible to work with POSIX regexps that don't even understand .+?, ala the Apache mod_rewrite engine. Dammit.]

In any case, there you go : you learn something every day, folks.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : reading, sites, source, code, php

  1. Create Table - Mysql Code - Help
    (1)
  2. Php Source Code Unveiled In Browser?
    is that possible? (7)
    I am quite new to PHP and this concern came to my mind after playing around a bit with it... When
    PHP is not correctly configured on the web server the source code of a php file we try to access
    through a browser will be shown instead of the result of the code itself. This will normally not
    happen when PHP is working properly, but I was just wondering if it could still be possible to see
    that code if a user wanted to or if something on the server failed. This would for example expose
    sensitive information like mysql passwords and so on... Is anything like that possib....
  3. Malicious Code Injection
    (3)
    Hi everyone! This is my first post, so be kind! Basically, I'm trying to get a free
    host together so am writing some posts. Here's a little summin' summin' about malicious
    code injection with PHP applications. Basically, this security exploit is one of the oldest tricks
    in the books and all comes down to the fact that PHP allows execution of both local and remote
    scripts with the SAME function... dur. Anyway, this is how it works. Image you've just employed
    a young go getter, straight outta uni, who has found becoming a Jack of all trades a ....
  4. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your
    help guys...I want to make a simple program that will some values and then store them on a database
    and then retrieve them...uhmm let me give an example out put of what i need. This is the example
    say..: Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those
    are the data needed for input values...my question now is how can I make a database....
  5. Reading Emails Using Php (imap)
    (0)
    Evening, ive been experimenting with PHP and IMAP (IMAP is a protocol used to read email messages
    without downloading them to a client like using POP) and I've come across a couple of issues,
    one of which i posted on the forums here but have since solved. But the solution highlighted another
    problem... It seems my simple code can only "detect" and therefore read/display NEW emails, which is
    a big problem so does anyone know how to read/display already read emails? If all else fails i can
    of course store all emails into a DB when the user reads them and retain them ....
  6. Php Calculator That Calculates Genetic Percentages?
    I need help finding sites or tutorials. (2)
    Okay, I have created, looked, and generally studied simple PHP calculators. However, I can not seem
    to find any tutorials on how to create a genetic calculator. One that calculates genetic percentages
    similar to that of Punnette Squares. I have seen plenty of websites that have these types of
    calculators, but I have yet to see any websites offer tutorials on how to create these types of
    calculators. So.. does anyone know of any tutorials I can find or sites that might have the tutorial
    I am looking for? Maybe even a tutorial here? Reason for asking: I am creating a webs....
  7. Best Sites For Learning Php-mysql
    (4)
    Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
    php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
    a better 1) but I wan't to know what is the best site for using php with mysql (using
    phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
    postgresql version of phpmyadmin whatever it's called looks better (visually)!....
  8. Php Code Needed Iii
    (10)
    Hello, everyone. I need your help again! Who might create the PHP code, the picture is
    above this text. Basically, I want when the user fill in all the information in this form, it
    automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
    said that your request has been sent. Moreover, if the user did not fill the entire information,
    the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
    that.....
  9. Php Code?
    Mathematical Applications (12)
    Hello, everyone. The help is needed again. How can I make calculator in PHP language? That will act
    like that a user just type in the fields known values, then click the button, and it's going to
    be solved automatically. In other words, have can I write a formula in PHP, how to plug it inside
    that language. For example, the formula to find a peremeter of square is: P=4a. So, a user
    just can write the known value which is peremeter itself and it will find the side of a square; and
    vice versa. If you can write many things how to do such formulas, such as comp....
  10. Php Code Needed
    Working Together? (5)
    Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
    registration form for my web-site using PHP and SQL. The information it should contain: 1) User
    Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
    to protect a random registration, for instance, 56+2=where user have to type an answer in order to
    finish registration. That's all for today. Anymore things, I will post another post over here.
    ....
  11. Php Code
    Needed?! (15)
    Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
    web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
    in, when you go to google, for instance. 3. He or she types her email address and it's going to
    be saved in my SQL database. 4. That's it. Help me if you can.....
  12. Use Rss In Php Code
    (3)
    so, how can I make RSS reader on my website? thanks in advance....
  13. Will This Code Work
    php linking script ?p= (5)
    hi i'm not that great at php so i'm not to sure if this will work or not. but what i want to
    do is be able to use ?p=staff or what ever page name, with out the php extion, and i would like to
    no if this simple script i made would work. the code is: CODE <?php $p =
    $_GET['p']; if ( !empty($p) &&
    file_exists('./' . $p . '.php') && stristr( $p, '.'
    ) == False ) { // pages = directory where you store your pages    $file = './'
    . $p . '....
  14. I Need Some Proof Reading For My Code Please! [resolved]
    (7)
    Well... everything is fine except the Content Select section (refer to the in-code headings)...
    thats where it says the error is... could anyone find out why it wont work when I click one of my
    links? http://2kart.trap17.com/progress.php for an example of what happens...
    //----------------- //portfolio paths //----------------- $portfolio = "/portfolio"; $lay
    = "/images"; //------------------ //navigation //------------------ $link = ·   Home
    html; $link = ·   Portfolio html; $link = ·   Programming html; $link = ....
  15. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE <?php //Save this as something like htmltest.php function
    CheckForm() { $html_unsafe=$_POST['code']; //Gives us our user
    input $html_safe=str_replace("<?php"," ",$html_unsafe);
    //Starts security measures $html_safe=str_replace("?>","
    ",$html_sa....
  16. Awesome Source Code Viewer Script
    (7)
    Hello! I have just came up with a sweet script to show the source code of any website and it
    only requires one file. This is the basis of the script and can be customized with CSS and other
    things and can be instituted as a public resource. Well I will provide the code and a step-by-step
    tutorial on each of its parts. This code has been tested by me. Enjoy! CODE <?php
    //This little tag starts our php script and is easily the most important part of the script. //We
    will start our base script here. //You can change some of the styles used here to your des....
  17. Whats Wrong>?
    please see this piece of code and see whats wrong: (9)
    CODE require('connection2.php'); $select=mysql_query("SELECT * from
    `users` WHERE password='$_GET[password]'");
    $co=mysql_num_rows($select); if ($co = 1) {
    session_start(); $s=session_id();
    $_SESSION['access']="yes";
    $username=$_GET['username'];
    header("location:../main/index2.php?a=$_GET[username]&s=$s"
    ;); //echo "<a href='.&....
  18. How To Make A Random 7 Number Code?
    (2)
    I am making a script in php, and for it I need to know how to make a random 7 digit code. I think it
    has something to do with md5, but i am not sure. Thanks! EDIT- Can someone please change the
    title to "How to make a random 7 digit code in php?" Thanks!....
  19. Php Education Class (first Code)
    (0)
    Hi I want to educate some PHP codes that i think they will be useful for all of you! My 1st
    code is this: CODE <?php class calculator {          /**      * Variable for holding all
    the numbers to add      *      * @var array      */     private $numbers = array();
             /**      * Variable holding all the digits after the point      *      * @var array      */
        private $afterPoint = array();          /**      * Maximum number of digits after
    the point      * that a number has      *      * @var int      */     private $....
  20. My Code Doesnt Resize Large Images, Please Help.
    (2)
    Can someone please have a look at the following code, this uploads an image, and make it in 2 sizes,
    one size is max. 600 x 800, uploads to images folder and second 120 x 120 and uploads to thumbs
    folder. this script works fine, with normal size images, but if i try to upload large pics( for
    example, an image with dimension 2432 x 3300, it shows blank page, and uploads the original image
    without sizing to "image" folder, and doesnt make any small thumbnail... I hope u understand..
    Please someone help me, i shall be so thankful. session_start(); header("Cache-contro....
  21. Some Basic Php Code Snippets For All Levels Of Experience
    (3)
    Most of the code snippets are usually used for community driven sites but they do give some general
    idea on how php works. Don't forget if your starting out php for the first time that when
    saving php files that you need to have the .php extension on your files or they will not work.
    Display Browser info This piece of code displays a user's browser info on how they are seeing
    the website CODE <?php echo $_SERVER["HTTP_USER_AGENT"]; ?>
    Actual Display- QUOTE Firefox - Mozilla/5.0 (Windows; U; Windows NT 5.1; ....
  22. Use Bb Code On Your Site!
    Just like on forums! (7)
    To use this you must have PHP support on your server. Just use this code: CODE <?php
    $content = "Hello, World!"; $html = array('[b]',
    '[/b]', '[i]', '[/i]', '[u]',
    '[/u]'); $replacements = array ('<b>',
    '</b>', '<i>', '</i>', '<u>',
    '</u>'); $content = str_replace($html, $replacements,
    $content); ?&....
  23. Good Source For Learning Php
    (13)
    http://www.bicubica.com/ This website explains everything about PHP, right from the basics. it
    also explains about Installing apache and PHP and configuring them. The site is very useful for
    newbies and also experts.....
  24. Wap Source Code Viewer
    Mobile/wap source code viewer page (4)
    This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
    work on web im sure ;-) CODE <? header("Content-Type:
    text/vnd.wap.wml"); echo '<?xml version="1.0"
    encoding="utf-8"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <head><meta
    http-equiv="Cache-Control" content="no-cache"
    forua="true"/></head> <card title="s60.nerds.....
  25. Dynamic Image / Signature Generator
    a simple code to change text on an image (12)
    In search of dynamically changing quote, saying or all other types of text on an image I came across
    a code that I have modified to fit my initial usage. This procedure requires two files and short
    knowledge of PHP. If you are familiar with Trap17's sig rotation code you will understand this
    procedure very fast. Code 1: dynamic_sig.php (you can rename this to index.php and you'll see
    at the end why) Code 2: a simple text file named anything (I will call it name.txt ) Code 1
    CODE <?php header("Content-type: image/png"); �....
  26. Adapting Html Code Embed To Work On Phpnuke
    Help With This Html Code Pls (7)
    QUOTE how can get this html code to work on my phpnuke site? what tags would i
    have to enable in the $Allowable HTML part of my config.php file?? Edited topic title. Moved
    to Programming. ....
  27. Just About Completed My Own Message Board Source.
    This one looks nice! (10)
    I've finally completed my message board source code! This one is very nice, and it has
    many, many features. So if you can, please rate them and possibly register if you like this
    /wink.gif' border='0' style='vertical-align:middle' alt='wink.gif' /> http://subzer0.net/boards/ ....
  28. Change Permission With Php Code
    code to change files' and folders' permissions? (3)
    As everyone know, there two ways (that I can think of) to change files' and directories'
    permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
    client that supports chmod. Well, I'm doing something for my site that requires files to have
    full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
    the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
    alternative to doing this is to change each file permission myself, but that would be....
  29. Php Clock
    source Code (7)
    Hi Every one i find this code its very easy simple php clock i think you can use it /blink.gif'
    border='0' style='vertical-align:middle' alt='blink.gif' /> CODE <? // Binary Clock //
    script copyright© 2002 Andreas Tscharnuter // questions? contact: psychodad@psychodad.at ||
    [url=http://www.psychodad.at/clock/]http://www.psychodad.at/clock/[/url] //
    free to use, copy and modify but leave comments untouched;) // just include this file where
    your binary clock should appear // version 1.2   03 September 2003 // below you can ....
  30. How do you test your php code
    (75)
    We know that php is a server side scripting language. So we will need a server with the php parser
    to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
    instal php and the server (apache) on your computer (localhost)....

    1. Looking for reading, sites, source, code, php

Searching Video's for reading, sites, source, code, php
advertisement



Reading Site's Source Code With Php - is this possible?



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE