Jump to content


Photo

Including scripts


  • Please log in to reply
16 replies to this topic

#1 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 24 October 2006 - 09:01 PM

Hello again ???

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

part of my index.php:
<?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
} 
?>


#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 24 October 2006 - 09:43 PM

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 - http://uk.php.net/include/

#3 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 24 October 2006 - 09:53 PM

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:
http://localhost/guestbook/gbook.php?a=sign

but link to the script is:

href="index2.php?op=1"
?

I got this script in guestbook directory.

You know what I mean?


#4 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 24 October 2006 - 09:59 PM

In that link to the php include reference, read Example 16-7 again. It addresses your problem exactly.

#5 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 24 October 2006 - 10:01 PM

I read:

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

?>

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

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

#6 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 24 October 2006 - 10:13 PM

In your switch block of code, for case 2 you need to supply the full URL to the file, not just the file name.


<?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
} 
?>


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

#7 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 24 October 2006 - 10:15 PM

Case 2 is a link from the script, to sign in the guestbook. Hav I do that for all links from the script???

#8 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 24 October 2006 - 10:18 PM

Only when you pass GET values into the file you wish to include.

#9 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 24 October 2006 - 10:19 PM

Ok. It's so difficult to me:) I don't uderstand all, but I will try:)

#10 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 24 October 2006 - 10:22 PM

Works, but when I clicked on add, i get 404:(

#11 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 24 October 2006 - 10:27 PM

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. :)

#12 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 24 October 2006 - 10:28 PM

File exist.

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

#13 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 24 October 2006 - 10:56 PM

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>

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

#14 doni49

doni49
  • Members
  • PipPipPip
  • Advanced Member
  • 515 posts
  • LocationCentral MO

Posted 24 October 2006 - 11:38 PM

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?
Don

#15 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 25 October 2006 - 07:56 AM

File exist, the path is surely good:

http://localhost/guestbook/file.php


#16 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 25 October 2006 - 01:40 PM

Maybe I wrote it little freaky:)
Once again:

I have index.php file. I'm including into it, other content files, this way:
<?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"); 
} 
?>

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.


#17 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 25 October 2006 - 05:57 PM

Everything seems to be alright, but why ex. sign guestbook isin't included in right div?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users