Jump to content


Photo

PHP Help Needed


  • Please log in to reply
8 replies to this topic

#1 meamrussian

meamrussian
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 April 2006 - 01:14 AM

Sorry about the undescriptive title. I couldn't think of the name of my problem.

I bought a MySpace friend train script, and I seem to be getting a problem.

[a href=\"http://www.mshangout.com/train/index.php\" target=\"_blank\"]http://www.mshangout.com/train/index.php[/a]

This is the error:

Warning: main(pages/.php): failed to open stream: No such file or directory in /home2/meamruss/public_html/train/pages.php on line 11
This is line 11:
include "pages/" . $page . ".php";

Throughout the whole script files, there is no such variable $page. However, the index page has only the following content:
<meta http-equiv="refresh" content="0;url=pages.php?page=home">

I'm guessing that "home" is $page in this case. The header (Home Page | Join the Train | What is the Train?) links have this format:
<a class="link_whitetored" href="pages.php?page=faq">FAQ</a>

Obviously, it assumes that it should load what's after the = for $page. But why isn't it reading what's after this = sign? It's just giving me pages/.php.

Sorry if that was confusing.

Thanks in advance.

#2 khendar

khendar
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 04 April 2006 - 01:27 AM

The problem is that this is probably an old script and uses outdated techniques for managing $_GET variables.

There used to be a setting called register_globals which meant that if you send a variable through the URL (as page.php?variable_name=variable_value ) in page.php the $variable_name variable will already be automatically set. There was no need to get it from the $_GET array. In your case $page is the variable that the script expects to be automatically set.

This functionality has since been removed (for security reasons i think) so you have to set $page manually by extracting it from the $_GET array. Add:

$page = $_GET['page'];

somewhere above the include line and it should work.

#3 meamrussian

meamrussian
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 April 2006 - 01:40 AM

Aha! That's the problem. It's using global variable. However, there is another part in the script that uses $post with POST instead of GET. How can I put them both in? I can't just put in

$page = $_GET['page'];
$page = $_POST['page'];

How can I use both?

Thanks.

#4 meamrussian

meamrussian
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 April 2006 - 02:43 AM

I fixed it by doing this:

$page.= $_GET['page'];
$page.= $_POST['page'];

Thanks for the help.

#5 khendar

khendar
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 04 April 2006 - 03:23 AM

No Probs

#6 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 04 April 2006 - 05:05 AM

The problem with this method is that you are adding $_GET['page'] to the end of $page and then $_POST['page'] to the end of $page so if the variable $page already exists it may not come out how you expected. Your way is very simple and works, but you should keep this in mind in the event you run into a problem with this in the future.

if ( $_SERVER['REQUEST_METHOD'] == "GET" ) $page = $_GET['page'];
if ( $_SERVER['REQUEST_METHOD'] == "POST" ) $page = $_POST['page'];

or

if ( isset($_GET['page']) ) $page = $_GET['page'];
if ( isset($_POST['page']) ) $page = $_POST['page'];

Just some food for thought.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#7 Guest_footballkid4_*

Guest_footballkid4_*
  • Guests

Posted 04 April 2006 - 06:35 AM

Or:
$page['GET'] = isset( $_GET['page'] ) ? $_GET['page'] : "";
$page['POST'] = isset( $_POST['page'] ) ? $_POST['page'] : "";

Then you can do things based on which one is set

#8 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 04 April 2006 - 07:46 AM

Now you have three examples. lol...Anyone else think of some more?

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#9 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 04 April 2006 - 05:51 PM

yes here is another example lol


if($_GET['page']==true){
echo "your Code here";
}
if($_POST['page']==true){
echo "your Code here";
}


The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users