Sunday, August 2, 2009

How do you open a web page from another webpage in PHP?

What code do I use to open another web page from the web page the user is currently has open.

How do you open a web page from another webpage in PHP?
Don't know coding but seems do me you would create a link. Most software usually has a command to highlight the area and create link.
Reply:Do you want to output a dynamic link on your site?





%26lt;a href="%26lt;?php print "http://yahoo.com"; ?%26gt;"%26gt;Link%26lt;/a%26gt;





%26lt;a href="%26lt;?php print $myvariablelink ?%26gt;"%26gt;%26lt;?php print $myvariable title ?%26gt;%26lt;/a%26gt;





%26lt;?php print "%26lt;a href=\"$myvariablelink\"%26gt;$myvariabletitl... ?%26gt;





Are you wanting to forward the user to a different page? (Must be sent before any output is printed.)





%26lt;?php


header( "Location: http://yahoo.com" );


exit;


?%26gt;





or (can be executed after output has already been sent to the browser, but requires javascript or a click)





%26lt;?php


print '%26lt;script language="javascript"%26gt;window.location = "http://www.yahoo.com";%26lt;/script%26gt;';


print '%26lt;noscript%26gt;Please click %26lt;a href="http://www.yahoo.com"%26gt;here%26lt;/a%26gt; to move along%26lt;/noscript%26gt;';


?%26gt;





Do you want to read in another web page and output it on your own? (Requires allow_url_fopen to be enabled in the configuration.) Be careful about doing this sort of thing, because if a hundred people hit your page, your server makes one hundred sudden requests to download. If this is the route you're after, look into cacheing/saving the result for a period of time or get fancy and ask the web server if the page has been updated.





%26lt;?php


$url = "http://www.yahoo.com";


$f = fopen( $url, "r" );


if( !$f ) die( "Could not open $url for reading" );


while( !feof( $f ) ) {


$data = fread( $f, 1024 );





// Print it out


print $data;





// Or store it in a variable


$text .= $data;


}


fclose( $f );


?%26gt;





Hope that helps.
Reply:Straight HTML %26lt;a href="http://www.example.com"%26gt;Text%26lt;/a%26gt; would create the link.





If you want to display the page within the page take a look at %26lt;iframe%26gt; or %26lt;?php include(''); ?%26gt;


No comments:

Post a Comment