Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Complete PHP newbie - undefined variable problem

Status
Not open for further replies.

BizzyLizzy

Technical User
Nov 3, 2003
77
AU
Hi hope someone can help me.

I have been given the task of updating and maintaining our company website which is fine as most of its written in html which I am used to dealing with. However, the new design template that we have been given is written in php.

I am getting an error showing in the apache error logs as follows:-

[Thu Dec 08 11:09:56 2005] [error] [client 127.0.0.1] PHP Notice: Undefined variable: view in C:\\Program Files\\Apache Group\\Apache2\\realdocs\\index.php on line 50
[Thu Dec 08 11:09:56 2005] [error] [client 127.0.0.1] PHP Warning: include(.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in C:\\Program Files\\Apache Group\\Apache2\\realdocs\\index.php on line 50
[Thu Dec 08 11:09:56 2005] [error] [client 127.0.0.1] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '.php' for inclusion (include_path='.;C:\\php5\\pear') in C:\\Program Files\\Apache Group\\Apache2\\realdocs\\index.php on line 50

Line 50 on the index.php code is as follows :-

<?php include ("$view.php"); ?>

and there are several lines further down that want to use the $view variable eg:

<td width="50%"><a href="index.php?$view=home"><font size="1"><img border="0" src="navi.jpg".....

I realise that the variable is undefined but how and where do I define it??

Can any explanations please be written in words of one syllable so that a complete moron (like me!) can understand.

Many thanks

Lizzy
 
You can simply define it anywhere in the php script prior to where it appears. Like so:
Code:
$view = '';
However, clearly $view should be something meaningful and we cannot tell what from what you told us. If I would be making wild guesses, $view is sent through the address line and so you should change all your $view occurances with [tt]$_GET['view'][/tt]. Or, if you want an easy way out, try:
Code:
$view = $_GET['view'];
 
Thanks for the quick reply!. However that error message turned out to be a bit of a red herring! We have a configuration problem with PHP somewhere along the line. I have uploaded the site to a webserver I use for testing and all is fine there. Its just when I try to run it locally that I get the problem.

I thought it might be an apache config problem but I get the same issues running it on IIS as well which narrows it down somewhat to PHP!

So if anyone has any further ideas of what config areas I should be looking at I would be enormously grateful.

Its a bit of a pain when developing or in my case rewriting a website to have to upload it each time you want to see what it looks like!

Ah well at least I can now get on with writing the new content.

Cheers

Lizzy
 
Since you still did not provide any information as to where variable $view should actually be coming from and since you say it works with another configuration, I am pretty sure it is what I predicted it to be.

It works on production server because it has register globals turned on, which means that $view exists because it is picked up from address line (or some other means of transporting variables between pages). That is a poor choice from the server admin, because leaving register globals on is a serious security hole. Read here why:
Your server, probably bundled with newer version of php (in newer versions register globals is off by default where it was on before), has register globals set to off and therefore has no idea what $view is meant to be. As before, I am asking you to tell me where $view is coming from. And as before, I am assuming it is coming from the address line and should be $_GET['view'] instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top