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.

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'

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

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.

got it to working

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.