1,105,331 Community Members

linking files in php

Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
0
 

is there a way to use real link in include? bc the code below doesnt work. it say cant use http.

  login.php
    <?php
          include("http://localhost/E_COMMERCE/INCLUDE/header.php");
    ...
    ?>
    ---------------------------------------------------------------------

    header.php
    ...
    <link rel='stylesheet' type='text/css' href='css/main.css' />
    ...
-------------------------------------------------------------------------------

another way in login.php, i can do this code below. but the problem is that css file doesnt get linked in login.php

include("../INCLUDE/header.php");

my folder set up or tree

>wampp
   >htdocs
        >E_COMMERCE
               >CSS
                    >main.css
               >INCLUDE
                    >HEADER.php
               >LOGIN
                    >login.php

another question is that which is better
../INCLUDE/header.php
vs
http://localhost/E_COMMERCE/INCLUDE/header.php
vs
E_COMMERCE/INCLUDE/header.php
i guess problem with 2nd link will be when you want to put your website online. than you will have to change your links bc it wont be localhost any more.

Member Avatar
gavinflud
Light Poster
46 posts since Dec 2012
Reputation Points: 14 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 0 [?]
 
1
 

As far as I'm aware, it is possible to include files from another server. There is a common security setting PHP sets to avoid this called allow_url_fopen which has to be changed. It is not good practice to do so though, because urls can change. The following is the best practice to implement:

<?php include('../INCLUDE/header.php'); ?>

As for your CSS file not being loaded in, that's because it's looking for it in the same directory as the login.php file. You'll have to set the href to '../CSS/main.css'

Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
0
 

thanks,

this is my log out scrip but not seem to get me log off. on echo it prints username so that means setcookie to null is not working.
logout.php

<?php
include('../INCLUDE/connect.php');

setcookie("id", "", time()-172800);
setcookie("username", "", time()-172800);

$c =$_COOKIE['username'];
echo"$c";
?>

the problem might be in my path bc i was changing it.

>css
     main.css
>image
>include
      connect.php
      header.php
>login_pages
      logout.php
      login.php
>index.php
Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
0
 

i kind of see the problem now.
i am setin up cookie in my login.php page.

<?php
session_start(); //for errors
....

setcookie("id", $id, time()+172800); 
setcookie("username", $username_p, time()+172800); //seconds - 2 days 
header("location: ../index.php");
...
$_SESSION['log_error'] = $log_error;
?>

for some reason cookie doesnt get safe when it goes to index.php.

Member Avatar
hwoarang69
Posting Pro
572 posts since Feb 2012
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 9 [?]
 
0
 

got it to working

Question Answered as of 1 Year Ago by gavinflud
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article