How to output the page generated from an included PHP script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sgjohns
Forum Newbie
Posts: 1
Joined: Sun May 20, 2007 1:24 pm

How to output the page generated from an included PHP script

Post by sgjohns »

I am attempting to output the page that is generated from an included PHP script in a new browser window, but have had no success in doing so.

The following generate_url.php script will generate a one time key that will allow a new user to download a file when they log in to my mambo based web site for the first time after registration. This script is included by the login script only if it is the new user's first login; fine so far. The problem is that I need it to pop a new browser window and output the generated page into this window. As written, the script will run, but the output cannot be seen because the login script process will then complete and the user will only see the site home page. Any help in doing this would be greatly appreciated.

<?php
/*
* generate_url.php
*
* Script for generating URLs that can be accessed one single time.
*
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );


/* Generate a unique token: */
$token = md5(uniqid(rand(),1));

/* This file is used for storing tokens. One token per line. */
$file = "/tmp/urls.txt";
if( !($fd = fopen($file,"a")) )
die("Could not open $file!");

if( !(flock($fd,LOCK_EX)) )
die("Could not aquire exclusive lock on $file!");

if( !(fwrite($fd,$token."\n")) )
die("Could not write to $file!");

if( !(flock($fd,LOCK_UN)) )
die("Could not release lock on $file!");

if( !(fclose($fd)) )
die("Could not close file pointer for $file!");

/* Parse out the current working directory for this script. */
$cwd = substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/"));

/* Report the one-time URL to the user: */

print "<a href='http://".$_SERVER['HTTP_HOST'].
"$cwd/get_file.php?q=$token'>\n";

print "http://".$_SERVER['HTTP_HOST']."/get_file.php?q=$token[/url]

\n";

?>
Last edited by sgjohns on Sun May 20, 2007 1:56 pm, edited 1 time in total.
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

Hi there!
Welcome to phpdn.
If you wrap that code in [ p h p ] tags the motivated people here will have a better view of that snippet ;)
Post Reply