Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Checking Variables In An Include


could anybody explain the following phenomen :

I have this line in my project :

include
"http://".$domain."/help/".$language."/".$defaultIndex."/".$help.".php";

This construct properly includes the file I need to. And the included
file contains the following line :

echo $domain;

- and on this place comes nothing: obviously, the variable '$domain' is
not set for the <help.php>.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Checking And Moving Variables ..
I have a variable called $Ident1 which is a few radio box selections and then I have $Ident2 which is a text box.

What I'd like to do is check to see if $Ident1 is not empty [no selections were made] and move it to $Ident .. but if $Ident1 happens to be empty [data filled in for $Ident2] I'll move $Ident2 to $Ident .. both variables are not int, Does anyone understand this and knows how to go about doing it?


Checking If Any Get Variables Are Parsed
is there a way of checking for the existence of any get variables (i.e.
unnamed)?

Checking For Empty Variables
Can I use empty() to check to see if variables actually have data? Basically I want the script or something to check to see if there is data in the variables. If there is no data, give the user some instructions on writing some data (link to a form or admin panel). If there is data, then continue with writing to the database.

Problems With Error Checking / Control Of POST Variables
I have a small form that on button press submits to a PHP file for further
processing into a database. I have to change the script as it allows
blank / nothing to be submitted to the database. The intention is that if
any of the two form fields are blank (empty) then the page is resent
stating that they have to fill in all the fields to post (to a database).

If I deliberately leave the fields blank and submit the form, querying the
database shows that both fields are zero / null - so nothing was entered in
to the database.

However, if I use an echo command to see what is going on (before the data
is entered into a database) I get the $TheName field with a "1" and the
$TheComment field with an unknown entry (it doesn't echo anything to the
screen - but it's not empty).

The code I've used to test this is:

$TheName = $_POST[gbName];
$TheComment = $_POST[gbComment];

if (($TheName = NULL) or ($TheComment = NULL))
{
echo 'Quick error check running:<BR>'
echo "Name: $TheName<BR>";
echo "Comment: $TheComment";
exit;
}

This does NOT execute as these fields are not empty. It only runs if I
change to:

if (($TheName = !NULL) or ($TheComment = !NULL))

Which is pointless as it will always execute with genuine entries.

Using the amended code below:

if (($TheName = !NULL) or ($TheComment = !NULL))
{
echo 'Quick error check running:<BR>'
}

echo "Name: $TheName<BR>";
echo "Comment: $TheComment";

I get the result that both the echoed lines are displayed as blank (no
"1").

Variables In Include?
Is it possible, sort of like you have an include like this:

include ("$variable.php")

I know it doesn't work like that, cause I tried it

Anyone know if its possible to get that to work?

Variables Through An Include
Hi ladies and gents. I'm still new to php and I under stand most of the concepts. I'm a front-end coder and designer, so I'm still trying to get my feet wet with the back-end. I've searched and scoured the board and some of my questions have been answered, but I still can't wrap my head around a problem I'm having. Here is the situation.

I have an index page that will load content based on the variable in the URL. This works perfectly fine. No issues there.

The problem is, I'm echo-ing $thisTitle variable in the <title> tags.
The $thisTitle variable is set in the home.php include file.
The index.php page calls the include and I thought the variable would get passed, but it doesn't.

I would like each of the includes to have unique variables that can be used or displayed on the main page. I figured keeping those variables within the include would be an easy solution, since the variables are unique to the include, instead of making a seperate file with variables associated to their includes. That would be another file to edit and would reduce its modularity.

So far from what I understand, one of the problems is that the home.php include is being called after the echo in the title.

Also, I know that the variables scope is only in the include. I know that global shouldn't be used and I don't want to get into a bad habit.

So is there a simple solution to this? Is there a better templating method then this?

For now I want to get this working with flat files. after this egg has been cracked I'll move into using it with a db.

I know I could be using some cms system, but the fact is I want to learn something and hopefully help some other beginners.

Thanks for your help ahead of time!

Here is the code simplified:

How To Include Using Variables?
I have a database that stores a few bits of info and then an URL for a file to be executed. Here's an example of a row from it..

name = BoxOfTricks
Cost = 2000
Pic = images/boxoftricks.gif
fileurl = items/boxoftricks.php

but when i pull the fileurl into a variable I can't seem to use that to make it include the file. Code:

Include With Variables - Why Does This Work ?
I am new to PHP and I do not understand why the following works ??

$file=urlencode("displayIncidents.php");
echo "<a href=statistics.php?fileName=$file&delete=true>Delete
Incident</a><br />";

When this link is selected the statistics.php simply includes the file
that passed to it - but why does it find the file and not try to load
the literal 'fileName=$file&delete=true' (that obviously does not
exist) ?

Using Variables As Filenames To Include
I'm trying to sort out a page where depending on who logs in, the menu changes. I have saved info in the session, and I want to use that info as a file name:

ex: $_SESSION['service'];
include($_SESSION['service']/$_SESSION['service'].php);

if some one is in computers, for example, it would include computers/computers.php. how do I get this to work?

Include Variables Update
I have a script form for search records from database. The script action lists the results and inserts them in a $_SESSION[selected] the problem is that i have a include file used to display the content of $_SESSION[selected] but it does get updated, I need to do a browser refresh for refresh for it to show current display, Is there a way to force update on the include file?

Parsing Variables In Php Include
I am trying to use the following include:

include "./file.php?foo=var1&bar=var2" ;

However its not working because the server is obiously looking for a file called "file.php?id=var1&bar=var2"  not just file.php then parsing the variables to it. I have read a few peoples sugestions in the includes manual liek settign the variable outside of the include and then passing it into the include itself ie

$vars= '?foo=var1&bar=var2' ; 

include './file.php$vars ; :

but that did what i thought it would and just spat back the same error. I am sure it's the variable thats causign the issue because when i take it away the include works  however this makes it so that my script doesn't work properly without manually setting the variable.

Pass Variables Via Include Command?
I've been trying to put amend a variable to the end of an include statement, but each time I do this, the variable isn't passed.

For example:

Pass Variables To Php Include File
I'm working on using an include file that is set up all good to go for an image gallery. The one thing I need to change though, is the path. My code is simple enough using the inculde PHP Code:

Passing Variables From A Text File Via Include()
what I'm trying to do is to make a sort of news posting script for a website that I've been working on. I am getting the text for the news from a form that the user fills out. The form has several different fields. For the sake of discussion, I'll refer to the values of these fields as

$title
$shortStory
$longStory

The values are then passed to a php file called write.php that will write the values to a file called news.htm, where the users will then be able to read the news. In order to make news.htm match the rest of the website, I've created a file called newsproperties.txt. This file holds 4 variables. It looks a little something like this.
PHP Code:

Include Gd-created Image AND Variables Used To Create It...
I am trying to make my own captcha. I have the image creation part done, but I can't get the image into an php/html page. I have tried include('file'), but it throw image/png headers, and confuses the script (does that make sense?).

Is there a way I can include the file that creates the image (image.php) as an image, along with the variables used to create it?  ($string for example)

MySQL Query Or Include Variables From File
I have a database table that rarely changes it's values. Would it be faster to insert the variables from that table into a file (and include that file into the PHP file that needs the value) or just query the database when needed?

I can run a script once I need to change the values and the script can write them to the file that is included in the PHP file that needs them.

If you don't know the answer can you tell me how I can test how much time a PHP script needs to run... can I find what time it is in a desired moment in the script in milliseconds or something?

Include Or Virtual Include: Neither Work For Subfolders
my includes files are all in my /ssi directory. I have many subfolders that call those includes files. Let's say I have a file like this:

/news/world/asia/thailand/index.php

In order to (relatively) call a file in the /ssi directory I have to use the following code:

<?php
include ("../../../../ssi/html-lang.htm");
?>

This is ridiculous. Everytime I make a new subfolder I don't want to have to add "../" to it. I heard about "virtual" includes but I'm not sure the syntax I'm using is correct (all I do is put 'virtual' after 'include'). Is there something I'm missing? Do I have to change the .htacess file? Help me please I'm going crazy. I don't want to resort to absolute referencing...

Error Says Can't See Include File, Yet Executes Some Code On Include File
I am using an include_once() command to include a file that sits a
level above the file view.php. when the code is run, I have an error
as follows:

Warning: include_once(../common.php) [function.include-once]: failed
to open stream: No such file or directory in C:Program Files..
view.php on line 2

Warning: include_once() [function.include]: Failed opening '../
common.php' for inclusion (include_path='.;C:Program Filesxamppphp
pear') in C:Program Files...view.php on line 2

The include command is simply: include_once(../common.php) - the '../'
before the 'common.php' to indicate a level above the current file
level. Is this right? I could not find a resource to confirm this.

The strange thing is that while the error seems to imply that the
calling file, view.php cannot 'see' the common.php file, other
functions called from the 'common.php' file executes correctly and on
the same calling file/page (view.php).

Appears to the a double take - quite confusing -

From SSI Include To PHP3 Include
Im trying to convert my pages to php and have a problem, how do I change from SSI include (.shtml) to PHP include (.php3) so that I still can have the last line in my script,
(?start=11&end=15 after the .php3)

I have tried this: <?php include ("ssi-top10-15.shtml?start=11&end=15") ?>

and it didnt work, I used to have it like this:

<!--#include virtual="ssi-top15-25.shtml?start=16&end=30" -->

This works, but it leaves out the scipt part: <?php include ("ssi-top10-15.shtml") ?>

Can't Include 'http...foo.php', But Can Include 'http...foo.txt'
This seems weird, but when I use the following code,

include 'http://www.foo.com/includes.php'

includedfunction();

I am told that it is a call to an undefined function, but
'includedfunction' is on the server.

the following includes work fine, and the run the called function with
no trouble:

include 'http://www.foo.com/includes.phtml'
include 'http://www.foo.com/includes.txt'

all three include.php,.phtml & .txt are on the server and are exactly
identical. I am running php version 4.1.1.

Same Named Variables.. Or Addressing Variables In A Loop
I'm just starting to program in PHP.. fairly new to programming in general... and I've run across a (probably simple) programming problem I hope someone can help me with. I'm sending variable names through an HTTP get that are generated through a foreach loop. The names are along the lines of name1=, begin1=, end1=, name2=, begin2=, end2=.. etc. The number is the number of the current cycle through the loop. My problem is addressing the variables on the next page... namely how do I evaluate those variables in a loop? I want the value of name1.. but obviously

for (i=1; i<3; i++)
{
echo "$name$i";
};

is not working. Is there an easy way to do this?

URL Checking?
how do you check if a browser came from a specific URL??

Checking For XSS ?
Does the check below ensure that the files are originating from my server,
i.e. to prevent or detect
any type of XSS ? Or is the HTTP_HOST easily spoofed ?

function test ($refer)
{
if (!stristr($refer, $_SERVER["HTTP_HOST"])) {
die();
} else {
}
}

test ($_SERVER["HTTP_HOST"]);

IP Checking
I have to do this for security measures on a script I am doing: To ensure the authenticity of the HTTP requests you should only accept requests from the following IP addresses: 80.87.132.0/26 (ie .0 -> .63) is there a simple way to do a range of IPs ie
IF $ipaddress == 80.87.132.* If not does anyone have a good function for this?

Checking %'s
Is there a built in function to check if a value is a certain % of a different value?

Like:
If($Value < 10% $value2)

sort of thing ?

Or do i have to work out the 10% first then check against that?

IP Checking
I have a rating system, and its supposed to let people vote only once but right now I can vote 50 times in a row if I want, and I dont know why its letting me vote multiple times, here is my code:

Spell Checking
How can i spell check without including the aspell or pspell libraries ( can't include them because i'm on a virtual host ). I don't mind if its an external service. Spellchecker.net was great, expect now you have to pay for it.

Checking A Field
I've seen a couple of form generation and validation scripts.

Checking Input Of An Url Or Ip?
i do use the following code:

Code:
if ($siteurl == "") {
$badreg = true;
$valid_url = false;
echo "<span class='main'><font color='#C10000'><b>Error:</b></font> Please check your url.<br>
";
} else {
$valid_url = true;
$siteurl = ereg_replace("http://", "", $siteurl);
list($domain, $file) = explode("/", $siteurl, 2);
$siteurl = "http://" . $domain . "/" . $file;
}

Any idea how i could extend the " if ($siteurl == "") { " for checking for valid domain names and ip-addresses?

Checking Mail
Is there any easy and quick way to check if a user got any/new mail with PHP? assuming that the user's mailbox is on the same system and the system is UNIX (Linux,BSD, etc.)

Checking If A Url Works
ok i need to check a url to make sure it works, and if it does, then
i want to print out "online", and if it returns 404 then i want to
print out "offline". how do i check if the url works or not?

Checking Paramters In The Url Bar
<?php
if ((!isset($s)) && (!isset($msg))) {
echo("<table>
....

I want some pictures displayed on the main page if its a new visit, but when they search and the url bar changes its skips displaying them, to save scrolling down all the time.

I tried the above to read the parameters but get an error when they are not set.

Is there something simple like this :

if (url has no parameters) {
echo("...draw front page section")

PHP And CGI Checking Of The Code
im trying to write a php app for my forums so when a user posts a message that has some programming code in it they can click on a link i plan on setting up that has a text box for them to paste the code into and hit a button (well call it submit) after they hit the button then the code is read and the syntax of this code is colorized much like Crimson editor does for its differant sytanx.

programming the checking of the code isnt my problem im having trouble figureing out a way to make it so when they inpute it it gets sent to a php program to be checked and then sent back with the proper color tages..so if they were to enter in the text box:

<?php
// blah blah blah
then soem more crap here
?>

they then hit submit the program checks it and sees the syntax for php so it coloriz's it as php syntax and sends back the text liek this

<?php
// blah blah blah
then some more crap here
?>
Quote:
and the code would looke liek this the [] are () so it doesnt show colors in this part but the code will be with the []
<?(color=blue)php(/color)
(color=green)// blah blah blah(/color)
then some more crap here
?>

and then when they copy and paste it into the forum its then colorized as php syntax, any ideas or a tutorial on how to get a CGI script to call a php file to runs checks would be great.

Password Checking
I enter my user name and password into the db as

"insert into prof (puserid,ppassword,p_fname,p_lname) values ('$puserid',password('$ppassword'),'$p_fname','$p_lname')";

This is entered into the db user with password encrypted. But when I try to login and compare it says invalid password. my query is:

$query = "SELECT pid from prof WHERE puserid ='$userid' and
ppassword=password('$pass')";

So in order to check what it is checking against. I did this
$test = password('$pass');
print "$test";

And it gives me a error saying

Fatal error: Call to undefined function: password() in c:apachehtdocsartprofpermislogin.php on line 52 and $test=password('$pass') is my line 52.

What could I do be doing wrong?

Password Checking
I am having a problem with a script that i am using for a user logging, especially regarding the password comparison. what i am trying to do is search mysql database for usernames from the user inputs. this should then put the results into the variable and then i am comparing the database password to the password the user entered.

if it matches then the user is logged into the system. Here is the code, any comments would make me a v happy man! I have declared all the database variables but i wont include them for obvious reason =) Code:

Credential Checking
I was wondering if you anyone knew of a good credentail checking
script to give me a starting point for some scripts.

Checking For Sessions
I have built a cms which is password protected. Each page uses a session to check for the password, and presents info if the password is registered. This all works fine on my server, but when I put it on the clients server, the session doesn't work. And yes, I have changed all the needed info to correlate with her server.

I think the session isn't working. Is there a way I can check the session functionality of the php engine. Like php.ini or something?

Checking URL Problem!!!
I've been writing a page to check whether a url is alive or dead. But
I keep having problem with my php function. The code below is my php
function and 2 urls to test (one is always alive and one is dead-not
valid).
============== check url function ==========
<?php

//This function return HTTP code.
function check_url($url){

// Break the URL down into its parts.
$url_pieces = parse_url ($url);
$path = ($url_pieces['path']) ? $url_pieces['path'] : "/";
$port = ($url_pieces['port']) ? $url_pieces['port'] : 80;
$host = $url_pieces['host'];

$fp = fsockopen ($host, $port, &$errno, &$errstr, 10);
if (!$fp) {
return "$errstr ($errno)";
} else {
fputs($fp, "HEAD $path HTTP/1.0

");
fputs($fp, "HOST: $host
");
fputs($fp, "CONNECTION: close

");

$data = fgets ($fp,128 );

//echo $data;

fclose ($fp);

$array = explode (" ", $data);
return $array[1]; // Return the HTTP code.
}
}

$url1="http://yahoo.com";
$url2="http://www.kdkdkdkdkdkdkdkdk.com";

$check1 = check_url($url1);

echo $url1." ".$check1."<br>";

$check2 = check_url($url2);
echo $url2." ".$check2;

?>
=============================================

The output that I have looks like 2 lines below:

http://yahoo.com 200
http://www.kdkdkdkdkdkdkdkdk.com 200

where 200 represents that a link is alive. However for the second url,
HTTP code can't be 200 because that url doesn't exist.

I don't know what wrong with my code,

Checking Path.
I have a script that allows the user to open a file in the server and show it, this is so new files can be published without having to modify the script. What I want to check is that the file requested is not outside the path so they can't access other files in the system. let's supose all the files are in: $COMUNET_ROOT/../public_files/ and the file is $page so I wrote this: PHP Code:

Error Checking
I have a classic problem: things run properly on my test server but don't
work on the live server (different PHP version, different master Apache
config, etc...) which I do not admin. In particular, for 'security reason'
the access to the error.log file has long been disabled and I don't get any
message on screen. Things just don't happen the way they should.

I've tried putting various takes on this in my .htaccess to no avail:
php_flag display_errors on
php_value error_log /home/dargaud/logs/error.log # Nothing there
php_value error_reporting E_ALL
php_flag html_errors on
php_flag log_errors on
php_flag track_errors on

What else can I try to troubleshoot issues without admin rights on the
server ?

Checking For Username...
How do I check in a mySQL table called 'Users' on column user_name when
registering a new user_name to make sure the new 'user_name' does not
already exist in that column?

Checking Other Sessions
I have implemented some login functionality using session variables which is quite straightforward and works well. Except for 1 requirement that I can't work out how to do.
I would like to prevent the same user from logging in more than once. But in order to do this I need to somehow see if that user is logged in already - i.e. check "other" sessions - is that possible?

Variable Checking
Does any one know if theres a way of checking that a variable just contains numbers and no letters or symbols.

Checking Date
if i use date() in php to get date, im getting date that my computer has right? wen i change that date of my computer, the date that i get from the function date() not be accurate. what php function i can use where i can get accurate date.

Checking If Ip's Are Still Up
I need to write a script that goes through a list of ips and see's if those ip's are still in use, or if they're dead. I tried using checkdnsrr but it returned false for every ip. Is there another function I should use? Is there an easy way to do this in Perl?

Checking Database
Is it possible to check the database to see if information being submitted is already present in the database?

Checking A Checkbox
Is it possible to preset the values of form elements with php - so that when
the client gets the page certain boxes are checked or completed - on the
fly - based on their HTML id.

Javascript has a way of doing this - but i need the functionality of PHP
too - so if i can move the whole thing over to php it owuld be better .

javascript example -

document.forms['form1'].elements['radiobuttonno'].checked = true;

Checking If A Site Is Available
What PHP code would I use to check if submitted sites to my directory
actually exist?? I want to use something that can return the server
code to me, ie HTTP 300 OK, or whatever. Can I do this with sockets?

Checking If Gd Has Already Installed
I installed php4.3.2 , apache 2.0.47 and mysql-standard-4.0.14.

1- it seems that they work properly , but i want to know how i can be sure if GD has been installed corrcetly. ??

2- BTW any clue about commands by which i can get the information ( like version ...) of a.m component??


Copyright © 2005-08 www.BigResource.com, All rights reserved