Passing vars from PHP

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
Alec
Advanced
Advanced
Posts: 19
Joined: Fri Feb 15, 2008 11:52 am

Passing vars from PHP

Post by Alec »

Hi Guys

I'm having problems passing vars from php to the menu_data file

I've renamed my menu_data file to menu_data.php as described in a topic on here, but it's still not passing the var.

The URL is http://locatea.net/modules.php?name=Cou ... ay&ref=coc

The var I'm trying to pass is &ref=coc

If you miss &ref=coc off the url, it loads the websites logo, if &ref=xxx it loads the members logo.

In the menu > Icons > Jobs > Jobs by day > Today's Jobs you will see the URL has &ref= on the end of it, but it doesnt pick up the var from PHP.

I've tried everything I can think of, inclding making global $ref; in just about everywhere but without luck.

My mil file is at http://www.locatea.net/mil/menu_data.php

Any ideas?
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Re: Passing vars from PHP

Post by Andy »

What exactly does the line look like in the .php file?

All I can see is aI("text=Only show vehicles;url=modules.php?name=Courier_Map4&mapcontent=vehicles"); but it's been parsed already so cannot see how you are calling the parameter
Alec
Advanced
Advanced
Posts: 19
Joined: Fri Feb 15, 2008 11:52 am

Re: Passing vars from PHP

Post by Alec »

Hi, the line in the data_menu.php file looks like this...

aI("text=Today's jobs;url=modules.php?name=Courier_Map4&display=today&ref=<?php echo $ref; ?>");

Thanks :D
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Re: Passing vars from PHP

Post by Andy »

Can you try this and let me know if it works:

Code: Select all

aI("text=Today's jobs;url=modules.php?name=Courier_Map4&display=today&ref=<?php echo $_REQUEST['ref']; ?>");
Alec
Advanced
Advanced
Posts: 19
Joined: Fri Feb 15, 2008 11:52 am

Re: Passing vars from PHP

Post by Alec »

Hi Andy,

Tried that one already, doesn't seem to work... It's in place now if you want to take a look.

:D
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Re: Passing vars from PHP

Post by Andy »

Hi,

You know what, it's actually working.

See here:

http://www.locatea.net/mil/menu_data.php?ref=1234

Then look at the source you'll see a ref=1234 in there.

What's happening is the parent page HAS the variable attached to it but the menu page does not.

So, in your html, instead of just this:

Code: Select all

<script type="text/javascript" src="mil/menu_data.php"></script> 
try this:

Code: Select all

<? echo "<script type='text/javascript' src='mil/menu_data.php?ref=$_REQUEST[ref]'></script>" ?>
This should pass the variable to the menu file.

HTH,
Andy
Alec
Advanced
Advanced
Posts: 19
Joined: Fri Feb 15, 2008 11:52 am

Re: Passing vars from PHP

Post by Alec »

Cool...

It worked, thanks for saving me a day of head scratching ! :lol:

Well pleased with the script guys, keep up the good work.

:D
Alec
Advanced
Advanced
Posts: 19
Joined: Fri Feb 15, 2008 11:52 am

Re: Passing vars from PHP

Post by Alec »

I forgot to add [ so others can do it ]

At the very start of menu_data.php add this

Code: Select all

<?php
$ref = $_REQUEST['ref'];
?>
then you can get the var using <?=$ref?> which saves a bit of space!

like this..

Code: Select all

aI("text=Today's jobs;url=modules.php?name=Courier_Map4&display=today&ref=<?=$ref?>");
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Re: Passing vars from PHP

Post by Andy »

Thanks for that.

That's how PHP used to be years ago before they introduced register_globals in their php.ini file.

If you change it to register_globals = On it will allow you to just access the form variable by name but it does open the script/server to possible security hacks.

Glad you got it working :D
Post Reply