How to control relative path in php - php

In my project, I have a problem for href.
my html page is a.php, and its code is :
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="http://www.ulpin.com /css/bootstrap.min.css">
<style>
dd{word-wrap:break-word;};
</style>
<title>SystemTitle</title>
<script type="text/javascript" src="static/js/jquery-1.7.2-min.js"> </script>
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
<base target="_self"/>
</head>
<body>
<br/>
<br/>
<br/>
<br/>
<div class="container">
<center>
ManTest<br/><br/>
</center>
</div>
</body>
</html>
But it works fail. So I checked the page source code with firefox, When I click the href of static/js/jquery-1.7.2-min.js, it shows:
Not Found
The requested URL /o1ws1v/web/admin/static/js/jquery-1.7.2-min.js was not found on this server.
The src is changed. "/o1ws1v/web/admin/" is added auto.
Why?
My fold struct is :
/yjdata/www/www/o1ws1v/web/admin/a.php
/yjdata/www/www/o1ws1v/web/static/js/jquery-1.7.2-min.js
/yjdata/www/www/o1ws1v/web/static/js/bootstrap.min.js
Otherwise, a.php is put in /yjdata/www/www/o1ws1v/web/, it works OK
Who can help me?

This is a simple problem of paths.
When you are under /yjdata/www/www/o1ws1v/web/admin/a.php and use src="static/js/jquery-1.7.2-min.js", this is waht happens :
--/yjdata/www/www/o1ws1v/web/admin/
| |--- a.php <-- You are here
| |--- static/ <-- This is where the browser think that the static folder exists
|--- static/ <-- This is where the folder really is !
So, what you need to do in the a.php is to go up a level in the src path :
<script type="text/javascript" src="../static/js/jquery-1.7.2-min.js"> </script>
The .. to indicate the parent directory.

Related

chrome net::ERR_ABORTED on one from several .css file

today I started some boilerplate project. I am using gulp to output minified css from SASS. I have two .css files - normalize.css and main.css. Both of them are minified from the same directory. When I am starting localhost with XAMPP I open index.php it could not load main.css but normalize.css is loaded. I get the following in console:
Also when I go to see files that are in localhost directory I see that main.css is there, but when I click on it it says that it could not found this file - error 404 and in url bar I see that it added "/" at the end of main.css - strange behaviour:
However when I open this index.php in Firefox everything is fine and both styles are loaded and displayed correctly. Here is index.php code if needed:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="" />
<meta name="keywords" content="">
<title>Title of site</title>
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="./dist/css/normalize.css">
<link rel="stylesheet" type="text/css" href="./dist/css/main.css">
<!-- FavIcon -->
<link rel="icon" type="image/png" href="//" sizes="32x32">
<!-- Fonts -->
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700' rel='stylesheet' type='text/css'>
<!-- JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Local -->
<!-- <script src="./js/jquery.min.js"></script> -->
</head>
<body>
<h1>Hello wosfsdfsdfrld!</h1>
<p>scss and sass</p>
<p><?php echo('THIS IS HEADERsfsfsdf'); ?></p>
<img src="./img/testimg.png">
<script type="text/javascript" src="./dist/js/app.js"></script>
</body>
</html>
So it seems that it is somehow related to Chrome Browser, what could be an issue? Maybe some XAMPP config? But I have never touched it
The problem was name of folder containing project "siteStarter-php" caused some conflicts - changed it to "siteStarterPhp" and everything is working

PHP include a file with an included file -> scripts and variables get included but seem echo'd

I am having troubles with including a file that has an included file with some js script library's in it.
index.php
<?php
include 'header.php';
?>
<section>
<div>
<p>misc. html</p>
</div>
</section>
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/footer.php');
echo 'test ='.$testVar;
?>
footer.php
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/includes/footerscripts.php');
?>
</body>
</html>
/includes/footerscripts.php
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<?php
$testVar = 'test';
?>
In that scenario, the index file does have this in the source code when ran:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
test =
The scripts are making their way there but are not being executed and the variables aren't coming through either.
When I change the footer.php to include those scripts and variable directly, the variable makes it to index.php, so do the scripts but they don't execute (or not on time?).
Any ideas guys?
I have a weird php5.ini file as I didn't know what all to put in it, if that makes a difference. The include file path seems okay as it still works for the most part.
Thanks,
Matt
Edit: Added the include ('header.php') which works fine and pulls in my header.
That file looks like:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="--">
<meta name="keywords" content="--">
<meta name="author" content="--">
<title>--</title>
<link rel="stylesheet" href="/css/mainstylesheet.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="icon" href="/images/favicon.ico">
</head>
<body>
<header class="nav-top" id="top" role="navigation">
<div class="container">
<div class="home-link">
<img src="/images/logo/logo-p.png" alt="plc" class="logo" />
</div>
<nav class="nav-main">
<ul>
<li>
Home
</li>
<li>
Portfolio
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
</header>
Edit: Guess I just needed my jquery loaded from the header of the document, because it works that way. I still can't carry variables from grandchild to parent but oh well
According to your example the index.php file is missing something:
<?php
include ($_SERVER['ROOT'].'/footer.php');
echo 'test ='.$testVar;
?>
I assume that you didn't post the whole file, since here the output hmtl here is not valid - missing html opening tag, etc. Could you please provide the whole and/or simplified index file?
Replace all instances of $_SERVER['ROOT'] with $_SERVER['DOCUMENT_ROOT'].

php page automaticly adding doublequotes to my page

I'm having a problem where my page automaticly puts two doublequotes outside php tags ("")
This happens as soon as the page contains <?php and ?> and I can't find out why.. Nor should it be my php settings because files in other directories work... except for this files somehow, here are the codes:
index.php
<html>
<?php include 'include/head.php' ?>
some data to test
</body>
</html>
head.php
<head>
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
</head>
<body>
<div id="test">test data</div>
and both of the CSS files are empty, I work with .css.php because I have been told that this could greatly improve loading speeds.. This all together gives me the following code in chrome, and Internet explorer:
<html>
<head></head>
<body>
"
"
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
<div id="test">test data</div>
"
somedatatotest"
</body>
</html>
EDIT: Real browser source:
<html>
<head>
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
</head>
<body>
<div id="test">test</div>
some data to test
Change your index.php file to this:
<html>
<head>
<?php include 'include/head.php' ?>
</head>
<body>
<div id="test">test data</div>
</body>
</html>
And your head.php file to this:
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
No questions, just do this. Promise it will solve your problem.
EDIT: Also, why is it common.css.php and not just common.css?
EDIT 2: Okay, do this then. You've got to atleast try some of the suggestions, otherwise no one will want to help you.
//index.php
<html>
<?php include 'include/head.php' ?>
<div id="test">test data</div>
</body>
</html>
//head.php
<head>
<link rel="stylesheet" href="style/common.css.php">
<link rel="stylesheet" href="style/header.css.php">
</head>
<body>
<div id="test">some head test data</div>
You're not passing a well formed HTML document to your browser, and the rendering engine is trying its best to show what it has got.
Since your HTML isn't well formed, you can't expect a predictable output. Fix your source, and the problem will be solved
Okay I found the problem, It seems that my Notepad++ settings were wrong, it would create files with the UTF-8 coding and ANSI enabled, but since I set my settings to UTF-8 (WITHOUT BOM) and ANSI coding ignored everything seems to be workign fine again.

why hyperlink with www does not visible

I was trying to make an hyperlink, I found something I don't understand.
The hyper link below doesn't show up on my html view with www in it.
href='http://www.ringtonematcher.com/co/ringtonematcher/02/noc.php?sid=EULDros&artist=$ringtone_artist&song=$ringtone_title
but when I remove www it start showing up
href='http://ringtonematcher.com/co/ringtonematcher/02/noc.php?sid=EULDros&artist=$ringtone_artist&song=$ringtone_title
Is there any explanation?
Thankyou
EDIT 1
Here is my view source
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/assets/css/style.css" type="text/css" media="screen" />
<title>Music Engine</title>
</head>
<body>
<div id="mainbody" class="wrapper">
<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
SC.initialize({
client_id: "6a43a20c7a9e04da8d722bb01f16ce49",
});
SC.get('/tracks/106285389',function(track){SC.oEmbed(track.permalink_url, document.getElementById("player"));})
$(document).ready(function() {
});
</script>
<div id="player"></div>
<a class="download" href="http://api.soundcloud.com/tracks/106285389/download?client_id=6a43a20c7a9e04da8d722bb01f16ce49">Download</a>
<div class="ringtone_matcher"><a class='download' href='http://www.ringtonematcher.com/co/ringtonematcher/02/noc.php?sid=EULDros&artist=Carly Rae Jepsen&song=Call Me Maybe'>Send Ringtone to your cell</a></div>
</div>
</body>
</html>
what i mean not visible is i can't see it in the browser but i can see it inside the source
www.ringtonematcher.com is on a list of unwelcome advertising sites in AdBlock, which applies a stylesheet which applies display: none to links to it. The site without the www. is not on that list.
Disable your AdBlock extension to see it.
The problem would seem to be from the fact that you aren't effectively "showing" the language of PHP that you have variables in your code.
<div class="ringtone_matcher">
<?php echo "<a class='download' href='http://ringtonematcher.com/co/ringtonematcher/02/noc.php?sid=EULDros&artist=".$ringtone_artist."&song=".$ringtone_title."'>";
echo "Send Ringtone to your cell</a>";
?>
</div>
This would, at least, be a more correct way of doing it.

Why is site_url hiding my html file

Im trying to hide my url for the css and only display the relative path. here is my html
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="<?php echo site_url('css/bootstrap.min.css'); ?>" rel="stylesheet" media="screen">
</head>
<body>
<h1>Hello, world!</h1>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Then when i view in browser my source code shows this.
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="
How do i fix this. The file im using is a php file.
Did you load the url helper?
$this->load->helper('url');
You can also Auto Load the helpers if you want to only load them once
To autoload resources, open the application/config/autoload.php file and add the item you want loaded to the autoload array. You'll find instructions in that file corresponding to each type of item.
CodeIgniter AutoLoad
I could not find the function site_url in the default php library, is PEAR enabled on your server?
if you want the relative path you could use:
<?php echo $SERVER['HTTP_HOST'].'css/bootstrap.min.css'; ?>
or just
../css/bootstrap.min.css
or directly from the root
/css/bootstrap.min.css

Categories