Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Stumped with printing a url in a php file.

Posted on 2004-09-06
4
260 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
ID: 11990645
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
ID: 11990663
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
ID: 11990877
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
ID: 11990946
im glad you got it sorted :)

|)iablo
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

789 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