PDA

View Full Version : Preventing pages to load on its own


AryaputrA
06-13-2003, 11:00 PM
here's my question,

i have a page called index.php with several <IFRAME> tags that loads other pages on my site for example a page like info.php

how do i make that whenever someone views the page info.php it doesn't display on its own, where else it gets directed back to the index.php page

like someone types mypage.com/info.php, it goes back to the mypage.com/index.php. i want visitors to access all the pages in my site by using the index.php page.

Is there a way of doing it ? is it done with php or javascript ?

missing-score
06-13-2003, 11:30 PM
I would have said javascript... ummm.... try:



if(parent.location != 'index.php'){
window.location = 'index.php';
}



mite work, im getting rusty with js :o, too much PHP ;)

AryaputrA
06-13-2003, 11:57 PM
Thanks,

but it didn't work, i insert your code to info.php(my example above), then when i view the index.php... :D ffffeeeewwiiittttt, the whole index.php page kept loading in my <IFRAME> for info.php

Is there a better way of doing it, if visitors are viewing it from index.php page there's no problem but if they're doing so from info.php on it's own they get redirected to the index.php page

raf
06-14-2003, 12:02 AM
Check out
http://www.wsabstract.com/script/script2/keepframes.shtml

Spookster
06-14-2003, 12:09 AM
You can do it with PHP as well.



<?php
if(substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/") + 1) == "info.php")
header("Location: index.php");
?>




PHP would be more secure as a person can just disable javascript but they can't stop PHP.

AryaputrA
06-14-2003, 12:37 AM
Spookster :

It didn't work,maybe i did something wrong, can i add like this :
<?php
if(substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/") + 1) == "info.php")
header("Location: ../../ index.php");
?>

another : where to add this line, can add this anywhere on my existing php page by just adding else at the end of your example line ?

raf:
i checked out that site , thx that script worked
<script>

//Break-out-of-frames script
//By JavaScript Kit (http://javascriptkit.com)
//Over 400+ free scripts here!

//if not in frames
if (parent.frames.length==0)
//CHANGE "index.htm" to the URL of your main frame page
window.location.replace("index.htm")
</script>

but i want it in PHP, coz Spookster mentioned that viewers can disable js

TQ

Spookster
06-14-2003, 01:59 AM
What version of PHP are you running? It works just fine.

Spookster
06-14-2003, 02:39 AM
Oh just noticed I forgot to put a slash in there. Use this:


<?php
if(substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/") + 1) == "info.php")
header("Location: /index.php");
?>

AryaputrA
06-14-2003, 03:49 AM
i did that too added a / infront of the index.php,
but it didn't work

i'm running php version 4.0.6

i downloaded the phpdev4_5A bundle from firepages

Spookster
06-14-2003, 06:31 AM
I should have figured. You really need an updated version of PHP. That one is quite old.

A slight change in the code here is what you need for the old version of PHP.



<?php
if(substr($HTTP_SERVER_VARS['PHP_SELF'], strrpos($HTTP_SERVER_VARS['PHP_SELF'], "/") + 1) == "info.php")
header("Location: /index.php");
?>

optimism_
06-14-2003, 10:58 PM
Originally posted by missing-score
if(parent.location != 'index.php'){
window.location = 'index.php';
}


try

if(parent.location.href != 'index.php'){
window.location.href = 'index.php';
}

AryaputrA
06-15-2003, 12:32 AM
Spookster:

ok, i've just downloaded the phpdev4.23 and upgraded it to phpdev 4.30, i have some minor problem on how to stop both Apache & MySql running, i'm over at the firepages forum, i'll sort that problem out first, then i'll return back here, so when i have the newer version of php i'll try your code again,:)
but if you can help me with the phpdev prob here, i'll be glad :D


Optimism_

Thanks but i want to do it with PHP, javascript works but i want it in php, see my previous posts why... :)

Nightfire
06-15-2003, 01:07 AM
No idea how the new phpdev packages work, but if you start the program with a .bat file, just simply open it with a text editor and dekete the line that runs mysql

AryaputrA
06-15-2003, 08:20 PM
Spookster:

OK im having php 4.2.3 now, but it still didn't work, is it that something has to be configured to my php ?

Spookster
06-15-2003, 08:23 PM
Originally posted by AryaputrA
Spookster:

OK im having php 4.2.3 now, but it still didn't work, is it that something has to be configured to my php ?

Error messages?

AryaputrA
06-15-2003, 08:37 PM
There was no error message, when i view info.php it doesn't go back to index.php( the original IFRAME page)

How if i have info.php and index.php in different folders ? ( not in this case, but just want to know)

Where shall i put the code that you gave, beginning of the page or end of the page ( page = info.php )

Will it work if i have HTML tags on the page ? currently i have html tags , so i pasted your code above the html tags.

Spookster
06-15-2003, 09:10 PM
I just realized this isn't going to work when using frames. Honestly though why would you need to use an iframe if you are using PHP? You can use PHP's include function to embed content from other files/pages.

For example:


main.php-

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
Here is the main page where the file info.php has been included below<br>
<br>
<br>
<?php
include("info/info.php");
?>
</body>
</html>



info.php-

<?php
if(substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/") + 1) == "info.php")
header("Location: /main.php");
?>
<table width="100%" border="0" cellpadding="5" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#CCCCCC">Here is the info inside the file info.php</td>
<td>&nbsp;</td>
</tr>
</table>


Here is this example in action:

http://www.designqueue.com/info/info.php

AryaputrA
06-15-2003, 10:15 PM
Now i'm getting error messages :

Warning: Failed opening 'info.php' for inclusion (include_path='.;C:\IBserver\php\includes;C:\IBserver\php\pear') in c:\ibserver\www\news\shout\index.php on line 11

What does that mean ?

Source for the index.php is as follows :

<html>
<head>
<title>Welcome</title>
</head>

<body bgcolor="#393939">

<table border="0" width="350" cellpadding="0" cellspacing="0">
<tr>
<td><?php
include("info.php");
?></td>
</tr>
</table>


</body>
</html>

Secondly :

I don't know what i did, your previous code worked with the IFRAME index.php page, when i viewed the info.php page, it went back to index.php but now the whole info.php page keeps loading....and loading...and loading, i have to stop or close the browser, now the question :

Can we add else command on your code, so that when the page info.php is actually viewed under the frame page of index.php ( nothing happen, everything is normal ) where else if the info.php page is viewed without the IFRAME page (index.php), it gets redirected to the IFRAME page index.php

Info :

On my info.php page i'm actually connecting to the db and displaying details stored in the db

Thanks

Spookster
06-15-2003, 10:21 PM
Originally posted by AryaputrA
Now i'm getting error messages :

Warning: Failed opening 'info.php' for inclusion (include_path='.;C:\IBserver\php\includes;C:\IBserver\php\pear') in c:\ibserver\www\news\shout\index.php on line 11

What does that mean ?

Source for the index.php is as follows :

<html>
<head>
<title>Welcome</title>
</head>

<body bgcolor="#393939">

<table border="0" width="350" cellpadding="0" cellspacing="0">
<tr>
<td><?php
include("info.php");
?></td>
</tr>
</table>


</body>
</html>

Secondly :

I don't know what i did, your previous code worked with the IFRAME index.php page, when i viewed the info.php page, it went back to index.php but now the whole info.php page keeps loading....and loading...and loading, i have to stop or close the browser, now the question :

Can we add else command on your code, so that when the page info.php is actually viewed under the frame page of index.php ( nothing happen, everything is normal ) where else if the info.php page is viewed without the IFRAME page (index.php), it gets redirected to the IFRAME page index.php

Info :

On my info.php page i'm actually connecting to the db and displaying details stored in the db

Thanks

Like I said before that won't work with iframes. When you load the page in the iframe it will always be accessed directly because an iframe is a completely seperate window from the current window.

As for your error you need to specify the correct path to the included file. That error is saying it cannot find the included file. It will first look in the path that you specify and then in the current directory and then it will go to the include path specified in the php.ini configuration file. If it cannot find it in any of those places it will give that error.

AryaputrA
06-15-2003, 11:22 PM
Ok i got the first one done but now :

Warning: Cannot add header information - headers already sent by (output started at c:\ibserver\www\news\shout\info.php:1) in c:\ibserver\www\news\shout\info.php on line 3

Ok, by this msg i know i can't add any html tags , echo or print commands, but how can i go about doing this ?

my info.php source:


<?php
if(substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/") + 1) == "info.php")
header("Location: /index.php");
?>
<?php

$con = mysql_connect("localhost","","")
or die("Unable to connect to db");


$database = "news";
$db = mysql_select_db("$database") or die("Unable to select db");


$sql = "select * from shoutbox order by id desc limit 10";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result))
{
$id = $row["id"];
$name=$row["name"];
$email = $row["email"];
$msg = $row["msg"];


echo "<b><font face=\"Verdana\" size=\"1\" color=\"#FFFF00\"><a href=\"mailto:$email\" target=\"new\">$name</a></font></b>:<font color=\"#FFFFFF\" face=\"Verdana\" size=\"1\"> $msg</font><br>";

}

?>
<form action="post.php" method="post" target="_self">
<input type="text" name="name" value="name" onfocus="this.value=''"><br>
<input type="text" name="email" value="email" onfocus="this.value=''"><br>
<input type="text" name="msg" value="message" maxlength="100" onfocus="this.value=''"><br>
<input type="submit" value="Shout">
</form>



all the files are in the same folder including info and index.

Spookster
06-15-2003, 11:44 PM
You can put whatever you want to in the info page. You just cannot output anything to the browser before sending the header. That means nothing before this


<?php
if(substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/") + 1) == "info.php")
header("Location: /index.php");
?>


not even a space before the <?php tag.

AryaputrA
06-16-2003, 12:09 AM
At last i got it!!! :D :D :D thanks to Spookster !!

Thank you very much Spookster

If i use the include function, i don't know if there'll be scrollbar like the one you get for using IFRAME, and by using this the whole page reloads, unlike IFRAME only that particular frame.

It works like a charm now, zoobie :thumbsup:

Spookster
06-16-2003, 01:03 AM
I would avoid using any kind of frames in a website. If the content is too much include without scrolling then you should just put it in it's own page and just link to it from the main page.

People in general really don't like scrolling a page to read and dislike scrolling a small box in the page even more.

AryaputrA
06-16-2003, 01:17 AM
Thank you very much for your advice