# Variables



## dudeking (Feb 7, 2007)

```
<?php
	if($video = ""){
		echo "
				Select a Video Below
			";
	}else{
		$toplay = array("wXkna1u_9mg","ZAekTEyH2Hc","x9pH160_oy8");
		$address = $toplay['$video'];
		echo "

		";
	}
	echo "$video";
?>
[URL=?video=0]
	0
[/URL]
[URL=?video=1]
	1
[/URL]
[URL=?video=2]
	2
[/URL]
```
http://safeinaroom.co.uk/include/site/videos/play.php

What's up with this??


----------



## MMJ (Oct 15, 2006)

Weird code. You don't seem to define *$video*.

If you explain what you are trying to do than I might be able to write something up for you.


----------



## dudeking (Feb 7, 2007)

basicly http://safeinaroom.co.uk/videos/ load of pics at the bottom, you click on one and it loads up the youtube video for it in the gray box.


----------



## MMJ (Oct 15, 2006)

Why don't you make each video in a separate html file, copying the code from the youtube site?

if you want them in the same page than do something like this:


```
<?php
$video = $_GET['video'];
if ($video == 0)
	echo "FIRST VIDEO CODE";
elseif ($video == 1)
	echo "SECOND VIDEO CODE";
elseif ($video == 2)
	echo "THIRD VIDEO CODE";
?>
```
If you run into trouble or don't understand than post back.


----------



## brendandonhu (Jul 8, 2002)

You might want to try it this way as well

```
<?php
	$videos = array('wXkna1u_9mg', 'ZAekTEyH2Hc', 'x9pH160_oy8');
	if(array_key_exists($_GET['video'], $videos))
	{
		?>
		[URL=http://youtube.com/v/<?php echo $videos[$_GET['video']]; ?>]http://youtube.com/v/<?php echo $videos[$_GET['video']]; ?>[/URL]

		<?php

	}
	else
	{
		echo 'Select a Video Below';
	}
	foreach($videos as $key => $value)
	{
		printf('[URL=?video=%s]%s[/URL] ', $key, $key);
	}
?>
```


----------



## dudeking (Feb 7, 2007)

Thanks for the help 

Think I'm going to use Brendan's code, seems like it would be simpler to add new videos.

Thanks again both of you!!


----------



## MMJ (Oct 15, 2006)

dudeking said:


> Thanks for the help
> 
> Think I'm going to use Brendan's code, seems like it would be simpler to add new videos.
> 
> Thanks again both of you!!


Yeah I didn't see what you were trying to achieve with your code, bren did.


----------



## brendandonhu (Jul 8, 2002)

[tsg=yourewelcome]yourewelcome[/tsg]


----------



## dudeking (Feb 7, 2007)

Thanks again 

While im here lol, after upgrading the old server to PHP5 whole site died.
Now fixed it buy using shtml for the includes instead of PHP but only thing I need fixing is this.


```
<?php
	$ua = $_SERVER['HTTP_USER_AGENT'];
	if (strpos($ua,'MSIE') != false && strpos($ua,'Opera') === false)
	{
		if (strpos($ua,'Windows NT 5.2') != false)
		{
			if(strpos($ua,'.NET CLR') === false) return;
		}
	if (substr($ua,strpos($ua,'MSIE')+5,1) < 7)
	{
	echo"

	";
	}
	}
	echo"
		
	";
?>
```
I need a PHP5 version of that, at the moment it just kicks out a load of errors about $_SERVER


----------



## dudeking (Feb 7, 2007)

It changes all my PNG's to Gifs for IE6.


----------



## brendandonhu (Jul 8, 2002)

What's the error you're getting?

Also you might want to take a look at get_browser()


----------



## MMJ (Oct 15, 2006)

http://php.net/get_browser said:


> Note: In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the _browscap.ini_ file on your system.
> 
> _browscap.ini_ is not bundled with PHP, but you may find an up-to-date » php_browscap.ini file here.
> 
> While _browscap.ini_ contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory.


Maybe they didn't setup browscap.ini for the version 5 yet. Although I might be wrong.


----------



## dudeking (Feb 7, 2007)

Okay I'll take a look at that now.

Just another random question can I use SHTML in a PHP file? Or should I stick to pure PHP?

Sorry for the stream of questions I'm just trying to get my site back online


----------



## dudeking (Feb 7, 2007)

right! everything is working again now except that script ^^

and this which is the menu script!


```
<?php
	if (isset($about)){
		include('about.php');
	}elseif (isset($tech)){
		include('tech.php');
	}elseif (isset($media)){
		include('media.php');
	}elseif (isset($random)){
		include('random.php');
	}elseif (isset($com)){
		include('community.php');
	}else{
		include('main.php');
	}
?>
```


```
<table cellpadding="0" cellspacing="0" border="0" id="linkstable">
	<tr>
		<td class="back">
			<a href="/">
				Home
			</a>
		</td>
		<td>
			<a href="?about">
				About
			</a>
		</td>
		<td>
			<a href="?tech">
				Tech
			</a>
		</td>
		<td>
			<a href="?media">
				Media
			</a>
		</td>
		<td>
			<a href="?random">
				Random
			</a>
		</td>
		<td>
			<a href="?com">
				Social
			</a>
		</td>
		<td>
			<a href="/contact">
				Contact
			</a>
		</td>
	</tr>
</table>
```


----------



## dudeking (Feb 7, 2007)

No errors, just dosnt work lol

http://dudeking.co.uk


----------



## MMJ (Oct 15, 2006)

```
<?php
if ($_GET['about'])
	include('about.php');
elseif ($_GET['tech'])
	include('tech.php');
elseif ($_GET['media'])
	include('media.php');
//and so on...
?>
```
Try this.

It might be better if you wrote a switch though. If bren doesn't come up with something than I'll see what I can do...


----------



## dudeking (Feb 7, 2007)

Okay ill give that a go 
What do you mean by a switch though? I'm still prity new to PHP and programming all together lol


----------



## dudeking (Feb 7, 2007)

```
Notice: Undefined index: about in /home/fhlinux172/d/dudeking.co.uk/user/htdocs/include/menu/menu.php on line 2

Notice: Undefined index: tech in /home/fhlinux172/d/dudeking.co.uk/user/htdocs/include/menu/menu.php on line 4

Notice: Undefined index: media in /home/fhlinux172/d/dudeking.co.uk/user/htdocs/include/menu/menu.php on line 6

Notice: Undefined index: random in /home/fhlinux172/d/dudeking.co.uk/user/htdocs/include/menu/menu.php on line 8

Notice: Undefined index: com in /home/fhlinux172/d/dudeking.co.uk/user/htdocs/include/menu/menu.php on line 10
```
Nope


----------



## brendandonhu (Jul 8, 2002)

PHP has register_globals off, take a look at this: http://php.net/register_globals

Your links should look like this

```
<a href="?page=about">
```
And your code like this

```
$pages = array('about', 'tech', 'media');
if(in_array($_GET['page'], $pages)
{
  include_once($_GET['page'] . '.php');
}
else
{
  include_once('index.php');
}
?>
```


----------



## brendandonhu (Jul 8, 2002)

MMJ said:


> ```
> <?php
> if ($_GET['about'])
> include('about.php');
> ...


Empty strings are == to false so it's not going to get to any of the include()s there.


----------



## MMJ (Oct 15, 2006)

brendandonhu said:


> Empty strings are == to false so it's not going to get to any of the include()s there.


I don't understand fully...


----------



## brendandonhu (Jul 8, 2002)

I mean your if()s. The code inside them will never run, since the links on the page make those variables empty.


----------



## MMJ (Oct 15, 2006)

brendandonhu said:


> I mean your if()s. The code inside them will never run, since the links on the page make those variables empty.


Okay, yeah.

The reason I thought it might work was because for another page I had

```
if ($_GET['do'])
{
//code
}
```
And the link to it was *logout.php?do=Logout* and it worked. But now I see that was because I gave it a value. Interesting...

Do you know of a way to echo all $_GET data?

nevermind, got it by using a foreach statement. Do you know of another way?

@dudeking: This works.


```
<?
if (isset($_GET['about']))
    include('about.php'); 
elseif (isset($_GET['tech']))
    include('tech.php'); 
//and so on.
?>
```
and the link can be *index.php?about*

But you should probably go with bren's code.


----------



## brendandonhu (Jul 8, 2002)

MMJ said:


> Do you know of a way to echo all $_GET data?


print_r($_GET);


----------



## dudeking (Feb 7, 2007)

```
<?php
	$pages = array('about', 'tech', 'media', 'random', 'com');
	if(in_array($_GET['page'], $pages))
	{
		include_once($_GET['page'] . '.php');
	}
	else
	{
		include_once('main.php');
	}
?>
```
Gives this error, Notice: Undefined index: pages in /home/fhlinux172/d/dudeking.co.uk/user/htdocs/include/menu/menu.php on line 3


----------



## MMJ (Oct 15, 2006)

Do you have menu.php included into index.php?


----------



## dudeking (Feb 7, 2007)

yeah


----------



## dudeking (Feb 7, 2007)

But I get the same message when I look directly at /include/menu/menu.php


----------



## MMJ (Oct 15, 2006)

Is that all the code in menu.php?

Edit the files and put a lot of "enters" before the php start. I want to see if the line error changes.


----------



## brendandonhu (Jul 8, 2002)

That's not an error, just a Notice. Are you sure the code isn't working?


----------



## dudeking (Feb 7, 2007)

100% the code isnt working.

It includes main.php but that notice is there above it and the links which are in main.php when pressed put ?page=about into the address bar but it does not change the included file to about.php


----------



## dudeking (Feb 7, 2007)

Im using PHP5 with globles off


----------



## brendandonhu (Jul 8, 2002)

Are you linking to menu.php?page=about or main.php?page=about ?


----------



## MMJ (Oct 15, 2006)

The pages don't even seem to be there. (about.php, random.php, com.php)

2.Try this:

```
<?php
if (isset($_GET['page']))
{
    $pages = array('about', 'tech', 'media', 'random', 'com');
    if(in_array($_GET['page'], $pages))
        include_once("$_GET[page].php");
}
?>
```


----------



## brendandonhu (Jul 8, 2002)

Why? It's the same thing, except missing the quotes in $_GET['page'].


----------



## MMJ (Oct 15, 2006)

brendandonhu said:


> Why? It's the same thing, except missing the quotes in $_GET['page'].


It doesn't include main.php, that could cause trouble if it doesn't exist.


----------



## brendandonhu (Jul 8, 2002)

If the file doesn't exist, it will say that in the error, not undefined index


----------



## MMJ (Oct 15, 2006)

brendandonhu said:


> If the file doesn't exist, it will say that in the error, not undefined index


Of course, thats why I said "*that could cause trouble*", not "*that could be the trouble*". 

This way it is filename independent.


----------

