Is this possible? variables & txt files.....

This is a discussion on Is this possible? variables & txt files..... within the PHP General forums, part of the PHP Programming Forums category; Hi, I want to store lots of variables in a seperate .txt file called "file_list.txt" $mov1 = "...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-11-2003
mike
 
Posts: n/a
Default Is this possible? variables & txt files.....

Hi, I want to store lots of variables in a seperate .txt file called
"file_list.txt"

$mov1 = "blue.html";
$mov2 = "red.html";
$mov3 = "yellow.html";
$mov4 = "black.html";
$mov5 = "green.html";

then in my .php page I want to do something like this:

<?php
include ("file_list.txt");
include ("mydirectory/subdirectory/$mov");
?>

<br><br>

<a href=movie.php?mov=mov1>Link 1 Here</a>
<a href=movie.php?mov=mov2>Link 2 Here</a>


I know I could acheive this by simply using <a href=movie.php?mov=$mov1>Link
1 Here</a> but I don't want the url showing the direct path's of my
includes.

ie, I want to see this: "movie.php?mov=mov1" rather than
"movie.php?mov=mydirectory/subdirectory/blue.html

I don't have SQL, nor do I know how to use it, so is what I want to do above
possible? I've tried but can't do it thus far. I think I may be going wrong
by the way I'm referencing my .txt file??

many thanks



Reply With Quote
  #2 (permalink)  
Old 07-11-2003
Kurt Milligan
 
Posts: n/a
Default Re: Is this possible? variables & txt files.....

mike wrote:
> "Kurt Milligan" <kurt@atNOSPAMmilliganshome.net> wrote in message
> news:jZednexkzrpuJZOiU-KYuQ@comcast.com...
>
>>Use an array. Try this:
>>
>><?php
>>include ("file_list.txt");
>>include ("mydirectory/subdirectory/".$movies[$HTTP_GET_VARS['mov']]);
>>?>

>
>
> thanks, I've tried this but can't seem to get it to work. Can you please
> just tell me what me url would be to pass the variable?
>
> for example "movie.php?movies=mov1" ??



if you have the array:
$movies['mov1'] = "blue.html";

and you have the include:
include ("mydirectory/subdirectory/".$movies[$HTTP_GET_VARS['mov']]);

then your URL should be:
movie.php?mov=mov1

because "mov" is the index into the HTTP_GET_VARS array, the value of
which (in this example) is "mov1", which is then used as the index into
the "movies" array, which for that index has a value of "blue.html".

hth
Kurt



Reply With Quote
  #3 (permalink)  
Old 07-11-2003
mike
 
Posts: n/a
Default Re: Is this possible? variables & txt files.....

"Kurt Milligan" <kurt@atNOSPAMmilliganshome.net> wrote in message
news:tBOdnXGGOaSYVJOiXTWJgA@comcast.com...

>
> then your URL should be:
> movie.php?mov=mov1


thanks alot Kurt!! I got it to work with the above :-)

your help was very appreciated.

mike


Reply With Quote
  #4 (permalink)  
Old 07-11-2003
mike
 
Posts: n/a
Default Re: Is this possible? variables & txt files.....

"Kurt Milligan" <kurt@atNOSPAMmilliganshome.net> wrote in message
news:tBOdnXGGOaSYVJOiXTWJgA@comcast.com...

>
> then your URL should be:
> movie.php?mov=mov1


Just one more thing though. How do I plan for a visiting array?

for example, if I enter movie.php?mov=blah , there being no value for "blah"
the page spluts out some ugly code? what would you suggest is the best way
to get round this?

thanks again

mike


Reply With Quote
  #5 (permalink)  
Old 07-11-2003
Kurt Milligan
 
Posts: n/a
Default Re: Is this possible? variables & txt files.....

mike wrote:
> "Kurt Milligan" <kurt@atNOSPAMmilliganshome.net> wrote in message
> news:tBOdnXGGOaSYVJOiXTWJgA@comcast.com...
>
>
>>then your URL should be:
>>movie.php?mov=mov1

>
>
> Just one more thing though. How do I plan for a visiting array?
>
> for example, if I enter movie.php?mov=blah , there being no value for "blah"
> the page spluts out some ugly code? what would you suggest is the best way
> to get round this?
>
> thanks again
>
> mike
>
>


a couple ways; you can check for the existance of an array value, like:

$filname = $movies[$HTTP_GET_VARS['mov']];

if(!$filename)
{
...do something to handle the error here...
echo "Sorry...";
}

also, you might want to check for the file existing before you "include"
it, like:

if(!is_file("mydirectory/subdirectory/".$filename))
{
...do something to handle this situation...
}

-Kurt

Reply With Quote
  #6 (permalink)  
Old 07-11-2003
mike
 
Posts: n/a
Default Re: Is this possible? variables & txt files.....

"Kurt Milligan" <kurt@atNOSPAMmilliganshome.net> wrote in message
news:gN2dne4IkYxZmpKiXTWJkA@comcast.com...

> a couple ways; you can check for the existance of an array value, like:
>
> $filname = $movies[$HTTP_GET_VARS['mov']];
>
> if(!$filename)
> {
> ...do something to handle the error here...
> echo "Sorry...";
> }
>
> also, you might want to check for the file existing before you "include"
> it, like:
>
> if(!is_file("mydirectory/subdirectory/".$filename))
> {
> ...do something to handle this situation...
> }
>


I can't get either of those to work correctly, ie when movie.php?mov=blah
the "sorry" message appears, but when "movie.php?mov=mov2" is a valid
variable value in the array the "sorry" message still appears...I have

<?php

include ("file_list.txt");
include ("movies".$movies[$HTTP_GET_VARS['mov']]);

$filname = $movies[$HTTP_GET_VARS['mov']];

if(!$filename)
{
echo "Sorry...";
}
?>


Is this wrong? I've tried doing this with the later part too:

if(!is_file("mydirectory/subdirectory/".$filename))
{
echo "Sorry...";
}
else
{
include ("movies".$movies[$HTTP_GET_VARS['mov']]);
}


Obvioualy I'm going wrong. Basically my arrays could end up being like this:

$movies['mov2'] = "red.html";
$movies['mov3'] = "blue.html";
$movies['mov4'] = "";
$movies['mov5'] = "yellow.html";

so if movie.php?mov=mov4 doesn't exsist I want to put some code to avoid
having errors or blankness.

thanks again

mike



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:59 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0