Web Hosting Talk







View Full Version : Help with my php script please


latheesan
08-16-2005, 06:40 AM
I've done my index page using php switch function, so i can have my header and the footer static and the middle bit rotation on request to right page.

e.g.


<?php

define ("IN_SCRIPT", "true");

include ("header.php");

switch($id){

case "page1";
include ("page1.php");
break;

case "page2";
include ("page2.php");
break;

case "admin";
include ("admin/index.php");
break;

default:
include ("home.php");
break;

}

include ("footer.php");

?>


Then on the page1.php, i have this drop downlist that shows a list of albums in the database, and when one album is clicked. it goes to the view.php?id=album name like this

i didnt wanted the user leaving the page index.php?id=page1 so what i did was created another similar php switch function like this:


<?php

if ($view == "view"){
include ("view.php");
exit();
}else{

if (!defined('IN_SCRIPT')){
echo "Sorry, you can't access this page directly!";
}
else{

//The real content
echo " A HTML TABLE WITH A DYNAMIC DROPDOWN LIST OF ALL THE ALBUMS IN THE LIST IS HERE ";
}
}

?>


so, i go to the page1 by accessing http://www.mysite.com/index.php?id=page1

i see drop down list of albums, so i click on an album called "Summer" for e.g.

this request goes to the view.php file like this

http://www.mysite.com?id=page1&view?id=Summer

Here's the problem, i see the http://www.mysite.com/index.php?id=page1 refreshed, i dont see the results im suppose to see

to test if the files are working accordingly, i tpyed the address like this

http://www.mysite.com/view.php?id=Summer

and all the songs within the album "Summer" were displayed nicely.

:( So what's wrong with my coding, how comes it keeps refreshing, instead of showing the results like the view.php file at the url

http://www.mysite.com/index.php?id=page&view?id=Summer

???

hehachris
08-16-2005, 06:54 AM
http://www.mysite.com?id=page1&view?id=Summer
not a valid query -.- 2 '?'s

u have to use, for example, http://www.mysite.com?id=page1&viewid=Summer

latheesan
08-16-2005, 08:33 AM
Im sorry, i quite not understand

I tried to send the query like this http://www.mysite.com?id=page1&viewid=Summer

it still refreshing the page

do i need to change the coding in my drop down list?

this is how it looks like so far:


<?php

include ("admin/db.php");

$query = "SELECT * FROM main";
$result = mysql_query($query);

$num = mysql_numrows($result);

echo "<form name=\"dlist\">";
echo "<select name=\"list\" onChange=\"location=document.dlist.list.options[document.dlist.list.selectedIndex].value;\">";
echo "<option value=''>Album List . . . </option>";

$i=0;
while ($i < $num){
$album = mysql_result ($result,$i,"album");
echo "<option value=\"index.php?id=page1&view?id=$album\">$album</option<br>";
$i++;
}

echo "</select>";
echo "</form>";

?>

Burhan
08-16-2005, 08:46 AM
Your URI is not properly formatted, which is why it is not working. There should be only one ? in a URI that starts a query string.

Please read the RFC for the proper syntax for URIs.

Short answer : view&?id=$album <-- this is very, very wrong.

hehachris
08-16-2005, 12:19 PM
http://www.mysite.com?id=page1&viewid=Summer

id=page1 => include page1.php
viewid=Summer => in your view.php, use $_GET['viewid'] to define the condition(SELECT * FROM TABLE_NAME WHERE FIELD_NAME='$_GET['viewid']')

Tapan
08-16-2005, 12:49 PM
Hi,

What does this bit "define ("IN_SCRIPT", "true");" of code does ? I have seen it in many php script but i am not able to figure it out what it does ?

Please tell. Even phpbb uses this.

Thanks.

latheesan
08-16-2005, 03:31 PM
What does this bit "define ("IN_SCRIPT", "true");" of code does ? I have seen it in many php script but i am not able to figure it out what it does ?


lolz, its simple. basically, i have a index page that includes all the pages in my site like, contacts.php, login.php, register.php and so on so people only access pages by the index.php?id=what eva page name

to prevent people from accessing the included pages directly, u you add a code called

define ("WHAT_EVER_HERE", "true");

in the index page, and on the included pages, u add a line that first check if people are accessing the included file directly or if its being called from the index page like this:


<?php

if (!defined('WHAT_EVER_HERE')){
echo "Sorry, you can't access this page directly!";
}
else{

//The real content
echo " Print The Real Contents Here ";
}

?>



Thats all,
simple technique used if scripts like phpNuke ;)