Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-31-2007, 03:13 PM
Frantic's Avatar   
Frantic Frantic is offline
Learning Programmer
 
Join Date: May 2006
Posts: 92
Rep Power: 10
Frantic is on a distinguished road
Default PHP reading a webpage Source vs Content

When I use this code below:

php Code:
  1. <?php
  2.  
  3.   // Open a site and read the contents
  4.   $read = fopen("http://www.gmail.com";, "r")
  5.     or die("Couldn't open file");
  6.    
  7.   // Read the bytes
  8.   $contents = fread($read,10000000);
  9.  
  10.   // Display the contents
  11.   echo "$contents";
  12. ?>

I see the actual page..... How do I see just the source though?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 10-31-2007, 05:07 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

It's been a while, but I believe $contents does contain the actual source code, its just when you echo it, the browser parses it.

Try a
PHP Code:
echo htmlentities($contents); 
If that doesn't work, you can always set the header to output text.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-01-2007, 08:10 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

You also seem to have an error on line 4:

php Code:
  1. $read = fopen("http://www.gmail.com";, "r")

See your extra ";" at the end of gmail.com?
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-09-2007, 05:12 PM
TkTech TkTech is offline
 
Join Date: Jun 2006
Posts: 990
Last Blog:
Having trouble with yo...
Rep Power: 20
TkTech is on a distinguished road
Send a message via MSN to TkTech
Default

Quote:
It's been a while, but I believe $contents does contain the actual source code, its just when you echo it, the browser parses it.
Righto! Easy fix, echo "<pre>$contents</pre>";
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-10-2007, 08:43 PM
ETbyrne's Avatar   
ETbyrne ETbyrne is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Lapeer, MI
Posts: 30
Rep Power: 4
ETbyrne is on a distinguished road
Default

I didn't know that you could read PHP source code with other PHP scripts! Kind of scary actually because then there is no real way to hide MySQL passwords!

EDIT: I tried both of those methods and they just show the HTML.

Last edited by ETbyrne; 11-10-2007 at 08:50 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 11-11-2007, 03:51 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Quote:
Originally Posted by ETbyrne View Post
EDIT: I tried both of those methods and they just show the HTML.
Thats what its suppose to do.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-11-2007, 07:37 PM
ETbyrne's Avatar   
ETbyrne ETbyrne is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Lapeer, MI
Posts: 30
Rep Power: 4
ETbyrne is on a distinguished road
Default

Oh, ok I see.
__________________
My website > www.evanbot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-12-2007, 12:50 AM
Jaan's Avatar   
Jaan Jaan is offline
Mod
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 930
Last Blog:
AdStar Ad Control Pa...
Rep Power: 16
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default

PHP Code:
<?php

  
// Open a site and read the contents
  
$read fopen("http://www.yoursite.xxx""r"
    or die(
"Couldn't open file");
    
  
// Read the bytes
  
$contents fread($read,10000000);
  
  
$contents htmlentities($contents);

  
// Display the contents
  
echo "<pre>$contents</pre>";
?>
here's your full script.. works perfectly
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 11-12-2007, 05:46 PM
TkTech TkTech is offline
 
Join Date: Jun 2006
Posts: 990
Last Blog:
Having trouble with yo...
Rep Power: 20
TkTech is on a distinguished road
Send a message via MSN to TkTech
Default

Quote:
I didn't know that you could read PHP source code with other PHP scripts! Kind of scary actually because then there is no real way to hide MySQL passwords!
WOW! Thats something completely different. You will NEVER be able to read a PHP source from another script over HTTP! EVER!
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 11-13-2007, 06:05 PM
ETbyrne's Avatar   
ETbyrne ETbyrne is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Lapeer, MI
Posts: 30
Rep Power: 4
ETbyrne is on a distinguished road
Default

Yeah the idea kind of scared me when I didn't read the first post correctly, but then I remembered how PHP works:

1. The user requests a page from the server.
2. If the page has PHP source code in it the server executes it.
3. The server sends the finished page to the user.

So the user never has a chance to see the source code.
__________________
My website > www.evanbot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP 4 end of life announcement Jordan Programming News 4 08-30-2007 10:55 AM
PHP Introduction clookid PHP Tutorials 10 01-16-2007 08:17 AM


All times are GMT -5. The time now is 05:45 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads