?
Solved

Stumped with printing a url in a php file.

Posted on 2004-09-06
4
Medium Priority
?
280 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 600 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

777 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