I'll try to make a script if the user is redirected to
http://example.com/?url=http://badsite.com
that the script reacts at the URL and displays an echo saying "Not secure", just like the Twitter and Google system, they also check if the URL is harmful.
I've found something, but this isn't what I was seaching for. Google couldn't help me, it gave me all vague answers.
<?php
$badsite = "http://badsite.com";
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == $badsite) {
echo "Secure, redirecting you";
} else {
echo "NOT SECURE";
}
?>
It isn't working as it should, it always displays "Not secure", while the link is secure. I think there's a error somewhere, but I need help fining it.
EDIT
<?php
$badsite = "http://badsite.com";
$host = $_GET['url'];
if($host == $badsite) {
echo "Secure, redirecting you";
} else {
echo "NOT SECURE";
}
?>
Ive tried, but it's still not working :(
Let me make the question a littlebit easier, how can I make it so if the url is
http://example.com/?url=Texthere
that there will be an echo on the page with "this is the page of texthere" and if "Texthere" isn't in the URL, that the echo won't be displayed?
Change your $host variable and if statement like that:
$host = "http://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host != $badsite) {
echo "Secure, redirecting you";
}
This worked just fine for me (tested).
You need to include http:// into your variable, and your if statement was wrong.
Related
i am getting an problem on loading my Template and i had tried testing my template on XAMPP and the same problem happened again
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at admin#main-hosting.eu to
inform them of the time this error occurred, and the actions you
performed just before this error.
More information about this error may be available in the server error
log.`
it doesn't show anything at first just loading page and then that error no more... please help but on XAMPP it just keeps loading my page
but after some time when i was trying to resolve the problem, found it and tried solving it but i need some help please on fixing the code which caused it before
$Domain = $_SERVER['HTTP_HOST'];
$Path = $_SERVER['PHP_SELF'];
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS']))
{
echo '<script type="text/javascript">window.location.assign("https://' .$Domain.$Path. '");</script>';
}
else
{
echo '<script type="text/javascript">window.location.assign("http://' .$Domain.$Path. '");</script>';
}
please some help ???
The reason is because each time your page is loading the script is running and refreshing the site endless. You need to know if the page have already been redirected.
example:
<?php
if (!isset($_GET['r'])){
$Domain = $_SERVER['HTTP_HOST'];
$Path = $_SERVER['PHP_SELF'];
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS']))
{
echo '<script type="text/javascript">window.location.assign("https://' .$Domain.$Path. '?r=https");</script>';
}
else
{
echo '<script type="text/javascript">window.location.assign("http://' .$Domain.$Path. '?r=http");</script>';
}
}
?>
I do not understand the point of this.. And I would recommend you to use Location instead. Example:
header('Location: http://www.example.com/');
This is a very poor way to reload a page.
The code below reloads the page infinitely until the url is modified...
To understand this, run the code below...
$Domain = $_SERVER['HTTP_HOST'];
$Path = $_SERVER['PHP_SELF'];
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
echo 'HTTPS AVAILABLE';
echo '<script type= "text/javascript">window.location.assign("https://' . $Domain .$Path. '");</script>';
} else {
echo 'HTTPS NOT AVAILABLE ';
echo '<script type="text/javascript">window.location.assign("http://' . $Domain .$Path.' ");</script>';
}
while the pages keeps loading, modify the code to this
$Domain = $_SERVER['HTTP_HOST'];
$Path = $_SERVER['PHP_SELF'];
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
echo 'HTTPS AVAILABLE';
echo '<script type="text/javascript">window.location.assign("https://' . $Domain . '");</script>';
} else {
echo 'HTTPS NOT AVAILABLE ';
echo '<script type="text/javascript">window.location.assign("http://' . $Domain .' ");</script>';
}
once saved this will redirect you to https://localhost or http://localhost
if running on your local machine.
The window.location.assign() reloads the page infinitely if the url is the same.
Situation is getting a logo on:
domain.com/special_dir/any_page
or
domain.com/special_dir/any_dir/
to use a link to [domain.com/special_dir/].
Everywhere else on [domain.com/] the logo must a link to [domain.com/]
This is what I have so far.
<?php
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if( $host == 'domain.com/special_dir/' ) {
echo '<div"><img src="..."></div>';
} else {
echo '<div"><img src="..."></div>';
}
?>
The logo for [domain.com/special_dir/] only works for [domain.com/special_dir/] URL, no others. I suppose the code it doing what it should, I just don't know how to make it recursive. I did search and read a lot of similar situations but none based on PHP code worked for me.
It is WordPress Multi-site setup and the "special_dir" is a regular sub-directory.
How to correct?
Thanks
Your if ($host == 'domain.com/special_dir/') statement means the special link will be printed for domain.com/special_dir/ only. It excludes everything else, including comain.com/special_dir/any_dir and domain.com/special_dir/any_page.
If think you want ...
if (substr($host,0,22) == 'domain.com/special_dir/') { ... }
This did the trick.
<?php
$url = $_SERVER["REQUEST_URI"];
if (strpos($url, "/special_dir/") === 0) {
echo '<div"><img src="..."></div>';
} else {
echo '<div"><img src="..."></div>';
}
?>
I've made this script, but the 4th line isn't right and I have really no clue how to solve this. I really appriciate if someone helps me. This is my code:
<?php
$url = $_GET["url"];
$badsite = array("http://check.com", "http://hotmail.com");
if($url == $badsite) {
echo "This URL is harmful.";
} else {
echo "Not harmful";
header("Location: " . $_GET["url"]);
}
?>
So the thing which doesn't work is the following line
if($url == $badsite) {
How can I make it so it checks if the GET contains a $badsite?
You don't want to check if the value equals the array, you want to check if it's in the array. Perhaps something like this:
if (in_array($url, $badsite)) {
// ...
}
Side note, you don't need (or want, really) this echo statement:
echo "Not harmful";
header("Location: " . $_GET["url"]);
You might get an error by emitting output before sending a header. But even if you buffer output or in some other way suppress that error, there's no reason to emit output when returning a redirect response. The browser would display it for only an instant, if at all. A redirect by itself is a complete HTTP response, no output is required.
In this case you can use the function in_array:
http://php.net/manual/en/function.in-array.php
<?php
$url = $_GET["url"];
$badsite = array("http://check.com", "http://hotmail.com");
if(in_array($url, $basite)) {
echo "This URL is harmful.";
} else {
echo "Not harmful";
header("Location: " . $_GET["url"]);
}
?>
I'd like to have my website redirect to the previous page after submitting login info.
I have searched around for this problem
I have echoed the contents of $url and even did strcmp and it evaluates true (not shown here)
Problem: The ELSE statement always evaluates even though $url == mlbmain.php OR course-website.php
Any suggestions?
<?PHP
require_once("./include/membersite_config.php");
echo "</br> </br> </br> </br>";
$url = isset($_GET['return_url']) ? $_GET['return_url'] : 'login.php';
//url now == to /mlbmain.php OR /course-website.php
$url = substr($url,1);
//url now == to mlbmain.php OR course-website.php
echo $url; //Just to make sure
$url = trim($url); //trim it to make sure no whitespaces
echo "</br>";
echo $url; //Just to make sure it's still the same
if(isset($_POST['submitted']))
{
if($fgmembersite->Login())
{
if($url == "mlbmain.php"){
$fgmembersite->RedirectToURL("mlbmain.php");
}
else if($url == "course-website.php"){
$fgmembersite->RedirectToURL("course-website.php");
}
else
$fgmembersite->RedirectToURL("index.php");
}
}
?>
After you press the Submit button you are making a POST request and the return_url variable will not be available anymore which was set with a GET request. You could create a hidden input field that will store the redirect_url and submit it with the form.
Since you say
It seems to be going to index.php by default
The problem is probably either with
if(isset($_POST['submitted']))
or
if($fgmembersite->Login())
and not related to $url at all.
I guess it can not find mlbmain.php or course-website.php at the current folder, so it throws 404 not found an probably you managed this error to redirect to index.php
I would like to know how to create a PHP IF Statement that detects if a user is loading/on a certain URL. In my case it's:
www.design.mywebsite.com
The IF Statement needs to cover the whole subdomain, EG the URL will also have to be detected:
www.design.mywebsite.com/filename.php
Once an IF statement is established, I want to add a PHP variable. So it might help others, let's call it:
$myvariable = "Hey there! You're on my subdomain";
So To Sum It Up:
The final code should look something like this...
<?php
if //Code to detect subdomain// {
$myvariable = "Hey there! You're on my subdomain";
}
?>
A simple solution is
$host = "baba.stackoverflow.com"; // Your Sub domain
if ($_SERVER['HTTP_HOST'] == $host) {
echo "Hello baba Sub Domain";
} else {
echo "not baba domain";
}
You can also use parse_url http://php.net/manual/en/function.parse-url.php if you have the URL
$url = "http://baba.stackoverflow.com/questions/10171866/detect-if-a-user-is-on-a-subdomain-and-then-add-a-variable-using-php";
$info = parse_url($url);
if ($info['host'] == $host) {
echo "Hello baba Sub Domain";
} else {
echo "not baba domain";
}
Please replace $url with $_GET ;