How to point to the address where the php is - php

Hello I`m trying to echo the address where my php is so for example this is my address:
http://domain.com/index.php?route=product/product&path=20_27&product_id=41
I want a php that returns "domain.com/index.php?route=product/product&path=20_27&product_id=41"
I`ve got thus far to domain.com/index.php using :
<?php
$address = $_SERVER["HTTP_HOST"];
$address1 = $_SERVER["PHP_SELF"];
$address3 = "http://$adres$adres1";
$address4 = $adres3;
$address5 = $_SERVER["PATH_INFO"];
echo "$address4"; ?>
Can someone pls hlp ?
thx

Try this:
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;

That's
$address = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]
To find out stuff like this is general create a php file with that content:
<?php
phpinfo();
?>
Open it in your browser and scroll to the bottom.

Related

Recieve Variable From php file Using fopen?

I've been working on a blogging system and I wish to receive information from external php files for a post's Title and Content, here is my code:
External (Blog Post's Content) File: 03-20-2018-This-Is-A-Test.php
<?php
$Title = 'This is a test!';
$Date = '03-20-2018';
$Content = 'Blog Post's content!';
?>
Client Side Page For Viewing Blog Posts: Post Home.php
<?php
$Title = '';
$Date = '';
$Content = '';
$GetDate = $_GET['d'];
$GetTitle = $_GET['t'];
$postPath = "Posts/$GetDate"."-"."$GetTitle.php";
$postFile = fopen($postPath,"rt");
$postContent = fgets($postFile,filesize($postPath));
?>
<!--Some HTML-->
<h2><? echo $Title; ?></2>
<b><? echo $Date; ?></b>
<p><? echo $Content; ?></p>
<!--Some More HTML-->
<? fclose($postFile); ?>
Client's Page URL: example.com/Post%20Home.php?d=03-20-2018&t=This-Is-A-Test
Reformatted as: example.com/03-20-2018/This-Is-A-Test
As you can see, I am using GET parameters to call the file that I wish to collect the information from.
I have tried using fopen which I wasn't able to get to work. Also include is forbidden with the particular server hosts I am using.
I am open to using file_get_contents if someone is able to help me get it to work.
Note: I have confirmed that my calling URL is correct and I get no errors from my php
So, I am trying to use fopen to collect the data of $Title $Date $Content from the file; 03-20-2018-This-Is-A-Test.php and use that information in the Client Side file; Post Home.php
I was able to find the answer using require().

PHP fetch with file_get_contents() funtion

i want to get m3u8 link from this site on other php page
for example : this is the site : "view-source:http://lideo.ru/embed/9528"
i want to extract only this m3u8 to other php page : http://hls.lideo.ru/liveapp/09528_bd608448e6c4a218d16b1f7b4018f6e8/index.m3u8?tokenhash=TIai4tLuWZHdLOS5mjNOqw
I'm tried this code but seems not working
$url = "http://lideo.ru/embed/9528";
$contents = file_get_contents($url);
preg_match('#m3u8([^"]+)#',$contents,$rtmp);
$link = urldecode($link[0]);
echo $link;
Any help please because i'm not soo good in php :)
thanks
Try this:
$url = "http://lideo.ru/embed/9528";
$contents = file_get_contents($url);
preg_match('/(https?\:\/\/[^\']*\.m3u8\?[^\']*)/', $contents, $result);
$link = urldecode($result[0]);
echo $link;

how to edit config php file with setting file

i have a little script and i want to give possibility to the user to edit the "config.php" file , with the script in the (setting.php) page .
For Example , they are some of codes in "config.php"
$title = 'myblog';
$email = 'info#google.com';
$desc = 'Something';
i want to have a "HTML" page , to get the value of the things that i said.
(the user enter the value and the value should be used in other parts of script)
if you want something like the user can change the title, if there are more than one user means if one changes config.php the title will be changed for the rest.
so, it's better to use a databases.
if it's only one user, you can use a file to store the information in.
please, explain more what you want to do, one user or more than one ?
You should better do this:
In the settings.php file:
<form action="settings2.php" method="POST">
Title:<input type="test" name="title"><br>
Email:<input type="test" name="email"><br>
Desc:<input type="test" name="desc"><br>
<input type="submit">
And settings2.php:
<?php
$title = $_POST['title'];
$email = $_POST['email'];
$desc = $_POST['desc'];
$content= '<?php
$title = "'.$title.'";
$email = "'.$email.'";
$desc = "'.$desc.'";
?>';
$file = "config.php";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
?>
These 2 pages will put in config.php the values submited by the form, for example:
<?php
$title = "PHP";
$email = "email#email.com";
$desc = "something";
?>

Wordpress custom field echoing whole URL

My code is as below:
<?php
if( get_field( "facebook" ) !== '' ): ?>
Facebook
<?php endif;?>
Instead of echoing the field's value which is (wwww.facebook.com), it's echoing it relative to the wordpress website.
Also, is my code efficient? Or is there a simpler way to do it?
Edit: What finally worked for me:
<?php
$website = (get_field('website'));
if(!empty($website)){
$final_url = (!preg_match("~^(?:f|ht)tps?://~i", $website))? 'http://'.$website: $website;
echo "$final_url" . "<br />";
}
?>
you should add http:// on the beggining to make external URLS
Facebook
or add http:// on your advanced custom field in the admin
EDIT:
here is your final code:
$url = the_field('facebook');
if($url!=""){
$final_url = (!preg_match("~^(?:f|ht)tps?://~i", $url))? 'http://'.$url: $url;
echo 'Facebook<br/>';
}
NOTE:
your data wwww.facebook.com has excess w
i appended the code given by #feeela so it would check if http:// is present, thanks to #feeela

Url and title with php snippet

I read several similar posts but I don't see my fault.
index.php looks like:
<head>
<title>Demo Title</title>
</head>
<body>
<?php
require_once "footer.php";
?>
</body>
footer.php looks like:
<?php
/*
* _$ Rev. : 08 Sep 2010 14:52:26 $_
* footer.php
*/
$host = $_SERVER['SERVER_NAME'];
$param = $_SERVER ['REQUEST_URI'];
$url = "http://".$host.$param;
echo $url;
$file = # fopen($_SERVER[$url],"r") or die ("Can't open HTTP_REFERER.");
$text = fread($file,16384);
if (preg_match('/<title>(.*?)<\/title>/is',$text,$found)) {
$title = $found[1];
} else {
$title = " -- no title found -- ";
}
?>
A request for the URL http://127.0.0.1/test/index.php results in:
http://127.0.0.1/test/index.phpCan't open HTTP_REFERER.
or for http://127.0.0.1/test/
http://127.0.0.1/test/Can't open HTTP_REFERER.
Any hints appreciated.
$_SERVER is an array which contains a bunch of fields relating to the server config. It does not contain an element named "http://".$host.$param, so trying to open that as a filename will result in the fopen call failing, and thus going to the die() statement.
More likely what you wanted to do was just open the file called "http://".$host.$param. If that's what you want, then just drop the $_SERVER[] bit and it should work better.
Note that because it's a URL, you will need your PHP config to allow opening of remote files using fopen(). PHP isn't always configured this way by default as it can be a security risk. Your dev machine may also be configured differently to the system you will eventually deploy to. If you find you can't open a remote URL using fopen(), there are alternatives such as using CURL, but they're not quite as straightforward as a simple fopen() call.
Also, if you're reading the whole file, you may want to consider file_get_contents() rather than fopen() and fread(), as it replaces the whole thing into a single function call.
try this:
$file = # fopen($url,"r") or die ("Can't open HTTP_REFERER.");
Try
<?php
$dom = new DOMDocument();
$host = $_SERVER['SERVER_NAME'];
$param = $_SERVER ['REQUEST_URI'];
$url = "http://".$host.$param;
echo 'getting title for page: "' . $url . '"';
$dom->loadHTML($url);
$dom->getElementsByTagName('title');
if ($dom->length)
{
$title = $dom->item(0);
echo $title;
}
else
{
echo 'title tag not found';
}
?>
I can see your trying to track the referral's title
You need to use $_SERVER['HTTP_REFERER']; to get that
what you want to do is something like this
$referrer = (!empty($_SERVER['HTTP_REFERER']) && !substr($_SERVER['SERVER_NAME']) ? $_SERVER['HTTP_REFERER'] : false);
if($referrer)
{
try
{
if(false !== ($resource = fopen($referrer,"r")))
{
$contents = '';
while($contents .= fread($resource,128))
{}
if(preg_match('/<title>(.*?)<\/title>/is',$contents,$found))
{
echo 'Referrer: ' $found[1];
}
}
}catch(Exception $e){}
}

Categories