473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Passing a HTML variable to a PHP file using include

From a html page menu I need to pass 2 variables.

<a
href="signup.php?var1=list-PINSS.php&var2=blurb-PINSS.php"><h3>Padre
Island National Sea Shore</h3></a><br>

These go to a php web page and are used thusly.

<?php include ($_SERVER["var2"]); ?//this is line 3
<?php include ($_SERVER["var1"]); ?// line 5

I am getting these error:
Notice: Undefined index: var2 in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 3

Warning: main(): Failed opening '' for inclusion
(include_path='.:/usr/share/pear') in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 3
Notice: Undefined index: var1 in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 5

Warning: main(): Failed opening '' for inclusion
(include_path='.:/usr/share/pear') in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 5

What am I doing wrong?

TIA
Dave

Sep 17 '06 #1
3 2379
You're using the wrong array. Variables passed as part of the URL are
found in $_GET, not $_SERVER - $_SERVER variables are more to do with
server information and information on the request itself, not data passed
with the request.
Sep 17 '06 #2
You are probably going to want to check the variable before shoving it
into the include, the URL looks a little suspicious with the ".php"'s
on in the get variables, it is not wrong but you may want to prevent
anyone from trying to take advantage of your script.

Something like this may suit you better:

<?php
// Create the include list
$includes = array();
// Fill it with the GET variables requested
$includes[] = trim($_GET['var1']);
$includes[] = trim($_GET['var2']);
// Loop through each file to include, verify it and include it
foreach($includes as $file)
if ($file != '' && is_file($file . '.php'))
include($file . '.php');
?>

Dave Kelly wrote:
From a html page menu I need to pass 2 variables.

<a
href="signup.php?var1=list-PINSS.php&var2=blurb-PINSS.php"><h3>Padre
Island National Sea Shore</h3></a><br>

These go to a php web page and are used thusly.

<?php include ($_SERVER["var2"]); ?//this is line 3
<?php include ($_SERVER["var1"]); ?// line 5

I am getting these error:
Notice: Undefined index: var2 in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 3

Warning: main(): Failed opening '' for inclusion
(include_path='.:/usr/share/pear') in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 3
Notice: Undefined index: var1 in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 5

Warning: main(): Failed opening '' for inclusion
(include_path='.:/usr/share/pear') in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 5

What am I doing wrong?

TIA
Dave
Sep 17 '06 #3
I agree with Nick, you want to control what the user can and can't do
at all times, and it seems like you could be allowing the user to
choose php files on your server, to edit or execute, both of which
could be used to take advantage of your application.

Nick

Nick DeNardis wrote:
You are probably going to want to check the variable before shoving it
into the include, the URL looks a little suspicious with the ".php"'s
on in the get variables, it is not wrong but you may want to prevent
anyone from trying to take advantage of your script.

Something like this may suit you better:

<?php
// Create the include list
$includes = array();
// Fill it with the GET variables requested
$includes[] = trim($_GET['var1']);
$includes[] = trim($_GET['var2']);
// Loop through each file to include, verify it and include it
foreach($includes as $file)
if ($file != '' && is_file($file . '.php'))
include($file . '.php');
?>

Dave Kelly wrote:
From a html page menu I need to pass 2 variables.

<a
href="signup.php?var1=list-PINSS.php&var2=blurb-PINSS.php"><h3>Padre
Island National Sea Shore</h3></a><br>

These go to a php web page and are used thusly.

<?php include ($_SERVER["var2"]); ?//this is line 3
<?php include ($_SERVER["var1"]); ?// line 5

I am getting these error:
Notice: Undefined index: var2 in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 3

Warning: main(): Failed opening '' for inclusion
(include_path='.:/usr/share/pear') in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 3
Notice: Undefined index: var1 in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 5

Warning: main(): Failed opening '' for inclusion
(include_path='.:/usr/share/pear') in
/var/www/vhosts/texasflyfishers.org/httpdocs/signup.php on line 5

What am I doing wrong?

TIA
Dave
Sep 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
14
by: Antoni | last post by:
Hello, I wondered if anyone could offer some guidance over my php script. I was hoping the example would allow the user to click the submit buttons and the item number increment. And when the...
3
by: Fredrik/Sweden | last post by:
Hi folks ! got this problem... i have a table 'Accounts' in my database, which contains a bunch of users. From the main menu i choose "edit user" and all users in the db are presented in a table....
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
1
by: jconnort | last post by:
I'm trying to write a function to get the current system time, so I can use it when I need to output it to a log, below is the code I'm testing: #include "include.h" #include <stdlib.h> ...
1
by: Dave Kelly | last post by:
I'm posting on this again. Sorry I am so thick heading but I do not understand why this failure. I have put in some 'printf' statements for debugging and some comments. And some questions. ...
2
by: Sike | last post by:
Hi everyone, I've been browsing this and a few other related newsgroups trying to get my head around this problem, and so far all the trails seem to go cold, without an acceptable solution being...
4
by: sofeng | last post by:
The following link shows a chart I created about passing structures among functions. Would you review it and tell me if it requires any corrections? ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.