Jump to content


Source Of a Site..?


9 replies to this topic

#1 Nerve

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 83 posts

Posted 02 October 2006 - 09:50 AM

Hello guys, I am making a coding to show the sites source, It is kinda like a proxy, But not really.

Use this:

	$url = "http://www.site.com";
	$lines = file( $url );
	
		foreach( $lines as $line_num => $line ) {

	echo "$line";

}

But when I run it, The images are /images/banenr.gif so it uses my banner.gif

How do I make it http://www.site.com/images/banner.gif instead of /images/banner.gif?

Also I have this problem with the CCS and linnks, can anyone help??


Thanks.

#2 NGPixel

    Senior Programmer

  • P2L Staff
  • PipPipPipPip
  • 1,410 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design : Coding : Animation

Posted 02 October 2006 - 11:59 AM

Just use str_replace ;)

	$url = "http://www.site.com";
	$lines = file( $url );
	
	foreach( $lines as $line_num => $line ) {
		$line = str_replace ("/images/", $url."/images/", $line)	
		echo "$line";
	}


#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 02 October 2006 - 04:31 PM

The catch is, not every site uses /images/ for their image directory, and then theres the problem of internal links, link tags in the url, etc... Plus, what if they already have the full path to their images for some reason (such as mod_rewrite)?

Easiest thing i can think to do is use preg_replace to find: src="foo" and then figure out of the full address is there or not (note, quotes are optional and can be single quotes), then add what ever you need to.

#4 cheerio

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Gender:Male

Posted 02 October 2006 - 05:23 PM

You can also just use file_get_contents()

#5 Nerve

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 83 posts

Posted 03 October 2006 - 05:48 AM

pc69, How would I use the preg_replace?

Edited by Nerve, 03 October 2006 - 06:18 AM.


#6 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 04 October 2006 - 06:20 PM

include the base href tag in the code
tons of ways to do that, but this will prolly work

str_replace('<head>', "<head><base href=\"$url\">");


#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 06 October 2006 - 03:42 PM

Again, what if the site already has a base tag, like my site does?
Then you would want to replace either it, or the closing head tag.

#8 Nerve

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 83 posts

Posted 07 October 2006 - 07:21 PM

Well thanks for your help, rc69 would it hurt to have a base tage 2 times then?

#9 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 08 October 2006 - 04:44 AM

View Postrc69, on Oct 6 2006, 08:42 PM, said:

Again, what if the site already has a base tag, like my site does?
Then you would want to replace either it, or the closing head tag.

The call to the style sheet is usually before the ending head tag, so it wont be picked up if you put the base tag there, your best bet would be to replace both the starting and ending head tag :love:

#10 Nerve

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 83 posts

Posted 08 October 2006 - 06:56 AM

So I would use:

str_replace('<head>', "<head><base href=\"$url\">");
str_replace('</head>', "</head><base href=\"$url\">");







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users