Solved

Stumped with printing a url in a php file.

Posted on 2004-09-06
4
234 Views
Last Modified: 2006-11-17
Here is the whole file, maybe something is interfering somewhere...

<?
ob_start();
include "phphits.inc.php";
phphitsAddHit();
//include("./includes/header.html");
require_once ('Benchmark/Timer.php');
$t = new Benchmark_Timer;
$t->start();
$no = no;
$file2 = $_GET["fileid"]; // get filename from the URL
include("db.php"); // connect to db
include("ipaddy.php");
include("domain.php");
$t->setMarker ('Queried the Database!');
$t->stop();
$result1 = $t->getProfiling();
ob_end_flush();
?>
<p align="center"><a href="http://www.mysite.net<? $file2 ?>"> Download!</a>
<body bgcolor="#0099CC">
<p align="center">Time to load page: <b><? print $result1[1]['diff'] ?></b</font>




The part I am having a problem with is this line:

<p align="center"><a href="http://www.mysite.net<? $file2 ?>"> Download!</a>

I've also tried

<p align="center"><a href="http://www.mysite.net<? print $file2 ?>"> Download!</a>  AND
<p align="center"><a href="http://www.mysite.net<? print $file2; ?>"> Download!</a>

When the page is loaded, the url is only http://www.mysite.net  The information loaded by the $file2 = $_GET["fileid"]; is not carried to the url.
0
Comment
Question by:go3team
  • 3
4 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 150 total points
Comment Utility
presumably your setting it up to pass the variable to the download file so the link should be something like

<p align="center"><a href="http://www.mysite.net?fileid=<?php echo $_GET['fileid']; ?>"> Download!</a>

Anyhow, is the variable definitely being passed in the query string, the should resemble http://www.yoursite.com/page.php?fileid=something
0
 
LVL 27

Expert Comment

by:Diablo84
Comment Utility
Something to note, if you are passing the file id between several pages it would be easier to use sessions rather then passing the variable in the query string.

eg.

first page:

session_start(); //BEFORE any output at top of page

$_SESSION['fileid'] = 23;

//OR $_SESSION['fileid'] = $fileid; OR $_SESSION['fileid'] = "id"; etc


then you can access this variable on any page just using

echo $_SESSION['fileid'];

NOTE: any page where you use sessions must ghave session_start(); at the top to initialize the session data
0
 

Author Comment

by:go3team
Comment Utility
Thanks Diablo, the first comment was what I was looking for.  What I was doing was using {REQUEST_URI} in my .htaccess file to add the filename to the ?file= part:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?,mysite.net(/)?.*$     [NC]
RewriteRule .*\.(avi|mpg|gif|swf|mpeg|wmv|mov|asf|mpe|mp3|ra|ram|AVI|MPG|GIF|MPEG|WMV|MOV|ASF|MPE|MP3|RA|RAM)$ http://www.mysite.net/test/sendfile.php?file=%{REQUEST_URI} [R,NC]

The other file ended up being:

<?
ob_start();
include "phphits.inc.php";
phphitsAddHit();
//include("./includes/header.html");
require_once ('Benchmark/Timer.php');
$t = new Benchmark_Timer;
$t->start();
$no = no;
$file2 = $_GET["file"]; // get filename from the URL
include("db.php"); // connect to db
include("ipaddy.php");
include("domain.php");
$t->setMarker ('Queried the Database!');
$t->stop();
$result1 = $t->getProfiling();
ob_end_flush();
?>
<p align="center"><a href="http://www.mysite.net<? echo $file2 ?>"> Download!</a>
<body bgcolor="#0099CC">
<p align="center">Time to load page: <b><? print $result1[1]['diff'] ?></b>font>

Working perfect!
0
 
LVL 27

Expert Comment

by:Diablo84
Comment Utility
im glad you got it sorted :)

|)iablo
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now