Jump to content

Archived

This topic is now archived and is closed to further replies.

pedro84

Including scripts

Recommended Posts

Hello again ???

I wanna to ask how to include external scripts, ex. guestbooks, etc.

part of my index.php:
[code]
<?php
if (isset($_GET['op'])){
switch ($_GET['op']) {
case 1:
    include("guestbook/gbook.php");
  break;
case 2:
    include("guestbook/gbook.php?a=sign");
  break;
case 3:
include ("sendtofriends/sendtofriends.php");
  break;   
default:
      include("news/show_news.php"); // this stops pageid to be set by the user trying to break your script
}
}

else {
include ("news/show_news.php");  //this one allows for just index.php to get default page
}
?>[/code]

Share this post


Link to post
Share on other sites
Not too sure what the question is? You are doing exactly that in your code you provided. Is something not working as expected?

PHP include reference - [url=http://uk.php.net/include/]http://uk.php.net/include/[/url]

Share this post


Link to post
Share on other sites
I have read it:(

Ok:)

This code is part of my index.php. I include content with switch and case. When I include ex. guestbook everything seems to be alright. But when I click on lnik from the script I got 404 error. I tired to repair links in script, but what to do when there's something that:
[code]http://localhost/guestbook/gbook.php?a=sign[/code]

but link to the script is:

[code]href="index2.php?op=1"[/code]
?

I got this script in guestbook directory.

You know what I mean?

Share this post


Link to post
Share on other sites
In that link to the php include reference, read Example 16-7 again. It addresses your problem exactly.

Share this post


Link to post
Share on other sites
I read:

[code]return.php
<?php

$var = 'PHP';

return $var;

?>

noreturn.php
<?php

$var = 'PHP';

?>

testreturns.php
<?php

$foo = include 'return.php';

echo $foo; // wyświetla 'PHP'

$bar = include 'noreturn.php';

echo $bar; // wyświetla 1

?>[/code]

This is the code, but how to put it in my site?

I don't understand that:) I'm neewbie:)

Share this post


Link to post
Share on other sites
In your switch block of code, for case 2 you need to supply the full URL to the file, not just the file name.

[code]

<?php
if (isset($_GET['op'])){
switch ($_GET['op']) {
case 1:
    include("guestbook/gbook.php");
   break;
case 2:
    include("guestbook/gbook.php?a=sign"); //You must supply the full URL here... for example, include("http://www.mydomain.com/gbook.php?a=sign");
   break;
case 3:
include ("sendtofriends/sendtofriends.php");
  break;     
default:
      include("news/show_news.php"); // this stops pageid to be set by the user trying to break your script
}
}

else {
include ("news/show_news.php");  //this one allows for just index.php to get default page
}
?>

[/code]

If you read the example 16-7 again you will see what I mean.

Share this post


Link to post
Share on other sites
Case 2 is a link from the script, to sign in the guestbook. Hav I do that for all links from the script???

Share this post


Link to post
Share on other sites
Only when you pass GET values into the file you wish to include.

Share this post


Link to post
Share on other sites
A 404 error means the file or URL you were linking to is not found. It normally means what it says, so check if the file/link for add exists. :)

Share this post


Link to post
Share on other sites
File exist.

I have to change links in the script file too??
Don;t understand  ??? ??? :'(

Share this post


Link to post
Share on other sites
[code]include_once 'header.txt';
echo '<h3 align="center">'.$settings['gbook_title'].'</h3>
<p align="center"><a href="'.$settings['website_url'].'">Back to '.$settings['website_title'].'</a>
| <a href="gbook.php">View guestbook</a>
| <a href="gbook.php?a=sign">Sign guestbook</a></p>
<div align="center">
<center>[/code]

This is a part code for the script. How to integrate it with my site?

Share this post


Link to post
Share on other sites
Pedro, it may very well exist--but the server's having trouble FINDING it.  Is the file in the same directory?

i.e. if the file containing the links is http://www.mydomain.com/myfile.html, then is gbook in the root of the site?

Share this post


Link to post
Share on other sites
File exist, the path is surely good:

[code]http://localhost/guestbook/file.php[/code]

Share this post


Link to post
Share on other sites
Maybe I wrote it little freaky:)
Once again:

I have index.php file. I'm including into it, other content files, this way:
[code]
<?php
if (isset($_GET['op'])){
switch ($_GET['op']) {
case 1:
  include('content1.php');
  break;
case 2:
    require('content2.php');
  break;
case 3:
include ("content3.php");
  break;   
default:
      include("news/show_news.php");
}
}

else {
include ("news/show_news.php");
}
?>[/code]

That's it.

Also I have downloaded questbook script. I have put this script in /guestbook/ directory. Now this script have links to other files, ex.

to write in the guestbook is => file.php.

The problem is that thoose files have to be included in my website. Even if I changed links to them, they open not included in my website.
       
............................
............................
.  .                      .
.  .                      .
.  .                      .
.  .                      .
.  .                      .
............................

Header, footer and left div don't change. They are the same al the time. I only include files in right, big div. This is the problem. When I include scripts, even I change links, subpages if the guestbook don't show in the right block. This is the problem:)

I hope You know what I mean.

Greetings
P.

Share this post


Link to post
Share on other sites
Everything seems to be alright, but why ex. sign guestbook isin't included in right div?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.