Solved

Stumped with printing a url in a php file.

Posted on 2004-09-06
4
276 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
[X]
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
  • 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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