i am using this code
<?php $_SERVER['SERVER_ADDR'].$_SERVER['PHP_SELF'];?>
this will give me http://209.84.172.15/New/index and i want this http://202.54.151.15/New
<?php echo 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); ?>
try this
<?php "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
Related
This is how i get my link
$link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
And this is how it looks when i echo it echo 'My link : ' . $link;
http://www.mylink.com/myfile.php?int=&int1=ASD++
But when i put my link in
echo "<a href='mailto:$mail&subject=Aktiviteter&body=$link'>Press on the link</a>";
I only get
http://www.mylink.com/myfile.php
So i miss my ?int=&int1=ASD++ , how can i get it to? Sorry if im unclear.
Your link is being considered part of the string that builds the email.
Your email client is seeing the request as:
subject = Aktiviteter
body = http://www.mylink.com/myfile.php?int=
int1 = ASD++
Because the email client doesn't know what to do with "int1", it ignores it.
To get around this, you'll want to encode your $link variable into the mailto URL using PHP's urlencode function.
Try this:
<?php
$link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$encoded = urlencode($link);
echo "<a href='mailto:$mail?subject=Aktiviteter&body=$encoded'>Press on the link</a>";
?>
echo "<a href='mailto:$mail?subject=Aktiviteter&body=$link'>Press on the link</a>";
after the email address you need to put ? not &
EDIT
this shold be the entire script, it works for me...
<?php
$mail = 'df#me.com';
$link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo "<a href='mailto:$mail?subject=Aktiviteter&body=$link'>Press on the link</a>";
?>
Try string concatenation.
echo "<a href='mailto:" . $mail . "?subject=Aktiviteter&body=" . $link . "'>Press on the link</a>";
How i include /master/header.php in /about/index.php?
localhost:8888/about/index.php:
<?php
include '/master/header.php';
?>
<?php
include '../master/header.php';
?>
Two dots mean back to main folder
Or:
include($_SERVER["DOCUMENT_ROOT"] . '/master/header.php');
I have some problems to put a URL-function within an if-statement properly. The following method works fine outside of my if-statement and the newly created link refers to this URL: "h**p://www.blog.com/?location=Bern&date=1"
<?php $rasp = $_GET["location"]; ?>
<a href="<?php echo preg_replace("/&date=(0|1|2|3)/", "", $_SERVER[\REQUEST_URI\])."&date=0"; ?> " >Heutel</a>
If-Statement works also just fine when I put simply an URL (e.g. https://www.google.com/) in between the quotation marks, then if I put the URL-function above in there, the newly created link refers to this: "h**p://www.blog.com/%3C?php%20echo%20preg_replace%28". Actually it should refer to the URL above "h**p://www.blog.com/?location=Bern&date=1"
URL-Function within if-statement:
<?php $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (false !== strpos($url,'date=1')) { echo
'<?php $rasp = $_GET["location"]; ?>
<a href="<?php echo preg_replace("/&date=(0|1|2|3)/", "", $_SERVER[\REQUEST_URI\])."&date=0"; ?> " >Heutel</a> ' ;
} else {
echo 'No cars.';
} ?>
Any ideas?
Solution thanks to IMSop:
<?php
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (false !== strpos($url,'date=1')) {
?>
<a href="<?php echo preg_replace("/&date=(0|1|2|3)/", "", $_SERVER['REQUEST_URI'])."&date=0"; ?> " >Heutel</a>
<?php
}
else {
echo 'No cars.';
}
This sequence makes no sense:
echo '<a href="<?php echo ...
A quoted string and direct output outside the <?php ... ?> markers are completely different things. The ' starts a string, which will continue until you put another '; the <?php would start a block of PHP code if you weren't in one, but you already are - if you weren't the echo wouldn't mean anything.
To join multiple strings together, you can use the . ("concatenation") operator:
echo '>Heutel';
Alternatively, drop out of PHP mode like you were before, but with the if in place:
<?php
// In PHP mode...
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (false !== strpos($url,'date=1')) {
// Now leaving PHP mode, but still inside the if condition...
?>
<a href="<?php echo preg_replace("/&date=(0|1|2|3)/", "", $_SERVER['REQUEST_URI'])."&date=0"; ?> " >Heutel</a>
<?php
// Re-enter PHP mode to close off the if statement
}
There's even an alternative syntax for control syntax which some people prefer to use in cases like this:
<?php
if ($some_condition) :
?>
your output here
<?php
endif;
?>
which is exactly the same as
<?php
if ($some_condition) {
?>
your output here
<?php
}
?>
I'm still learning php and I still haven't figured out when to use ' or ". I'm guessing thats the problem with this code. It redirects me to the right page but the $loc variable isn't carried over.
<?php header("Location: roomdata.php?loc=$loc"); ?>
on the page that has the header() commaned I also have an include command...
<?php include 'include/globalscripts.php'; ?>
and in the globalscripts.php is...
<?php if( isset($_GET['loc']))?>
<?php $loc = $_GET["loc"];?>
I would personally use:
<?php
header('Location: roomdata.php?loc='.$loc);
?>
<?php if( isset($_GET['loc']))?>
<?php $loc = $_GET["loc"];?>
TRY
<?php
if( isset($_GET['loc'])){
$loc = $_GET["loc"];
}
?>
Your code should work, are you sure $loc is defined at this point?
Regarding ' and ":
$value = "derp";
echo "the value is:\t$value";
//output: the value is: derp
echo 'the value is:\t$value';
//output: the value is:\t$value
How can I get my full current url in php but minus all querystrings?
Example
echo 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
Would echo something like assuming query strings were in place...
http://www.example.com/example?tab=foo&dslip=yes
How can I get the same as above but cut off all the query strings?
How is this done in php.
Thanks.
PHP_SELF is what you need I believe.
echo('http' . ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') ? '' : 's') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']);
Or the __FILE__ constant, depending on your exact configuration and situation.
Try this
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$part = explode('?',$url);
echo $part[0];
I think the solution is this:
echo 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
the $_SERVER['SCRIPT_NAME'] variable returns path of your script without the query string like you want.
if you like to see all variables available in php just try this
phpinfo();
Best regards