When I go to the home page of my website, it does not have a default id in url.
How can I set a default id to my home page's url.
I want this : www.afgclick.com&id = 2
Just add a check to see if and id is set, and if not, redirect to the same url WITH that id.
In PHP: (thanks #Albzi)
if (!$_GET['id']) $_GET['id'] = 1;
If you need that parameter in the URL but you dont own the link that gets you to that page then try using something like:
HTML version
Create an index.html file containing the following code in the head section:
<meta http-equiv="refresh" content="0; url=www.afgclick.com&id=2" />
Javascript version
<script>
setTimeout(function(){location.href="http://www.afgclick.com&id=2"} , 3000);
PHP version
function redirect($url, $statusCode = 303){
header('Location: ' . $url, true, $statusCode);
die();
}
Good luck!
Related
Hii Everyone,
Here is my code for facebook Signin.i got this example from http://www.codexworld.com/login-with-facebook-using-php/. here is my index page code
PHP code
<?php
include_once("config.php");
include_once("includes/functions.php");
//destroy facebook session if user clicks reset
if(!$fbuser){
$fbuser = null;
$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
$output = '<a class="myLink" href="'.$loginUrl.'">Click Here To Proceed</a>';
}else{
$user_profile = $facebook->api('/me?fields=id,first_name,last_name,email,gender,birthday,picture');
$user = new Users();
$user_data = $user->checkUser('facebook',$user_profile['id'],$user_profile['first_name'],$user_profile['last_name'],$user_profile['email'],$user_profile['gender'],$user_profile['birthday'],$user_profile['picture']['data']['url']);
if(!empty($user_data)){
$output = 'Thanks For Register With Spark.You Should Receive Confirmation Mail Shortly';
}else{
$output = '<h3 style="color:red">Some problem occurred, please try again.</h3>';
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Spark Login with Facebook</title>
<style type="text/css">
h1{font-family:Arial, Helvetica, sans-serif;color:#999999;}
</style>
</head>
<body>
<div>
<?php echo $output; ?>
</div>
</body>
</html>
Here i use a href to show facebook login.after te click of href it will redirecting to facebook login instead automatically want to click and it will redirect the page.Is there any possible way to do that.If anyone know the solution for the problem please help me!!
Why not do this with header location? Here´s how that works: PHP header(Location: ...): Force URL change in address bar
For example:
$loginUrl = $facebook->getLoginUrl(array('redirect_uri' => $homeurl, 'scope' => $fbPermissions));
header("Location: " . $loginUrl);
Official docs: http://php.net/manual/function.header.php
No need for using an $output variable, or for creating a login page (if you want to auto-redirect anyway). Just redirect the user if he is not logged in yet. No need to do something shady like "auto-clicking the login button". It´s not a solution, it´s a bad workaround. Although, it would be a lot better if you would let the user click it. Redirecting to the login page without a proper intro page, where he can see what the App is about, is not a good idea.
Even better: Use the JavaScript SDK for login: http://www.devils-heaven.com/facebook-javascript-sdk-login/
If you want to change the webpage's URL, you do not need to use jQuery to click the link. Instead, there is a simpler way.
JS:
window.location = "http://www.example.com/";
By changing the window.location, you can "redirect" to a new URL.
If you want to redirect only after an event, you can put that in a function of yours.
Example:
window.location = "http://www.example.com"
I have an url in ajax like this:
<html>
<header>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</header>
<body>
<?php
echo("<pre>");
echo "Hello: <span style='color:red'>".$user_data['user'];
echo("</pre>");
echo "<button id='play' id_user = '".$user_data['id']."' user = '".$user_data['user']."'>Chơi game</button>";
?>
<script>
$("#play").click(function(){
var user_id = $(this).attr('id_user');
var user = $(this).attr('user');
window.location= "<?php echo site_url('wellcome?user_id='.$user_data['id'].'&user='.$user_data['user']); ?>";
})
</script>
</body>
</html>
When i redirect to welcome Controller with 2 parameters then it shows a 404 error. How should i do pass that parameter to controller welcome? Thanks all!
Things to check for the redirect (not ajax) you are trying to do:
use window.location.href
are you certain, there's something at wellcome?... (welcome typically has a single letter l ?
check in HTML source view, what get's generated behind the equal sign. Does it look like a reasonable URL path?
obviously, you attempt a relative path, see further advice here how to do that.
Arguably better, change to an absolute path, using PHP $_SERVER Variables to glue it together, or at least start with a leading // (path and protocol-relative to your page)
I have a simple form which is inside IFRAME. When user click on SUBMIT, it redirects to a specific page on my server. The function I use for the redirect is
header ('Location: mypage2.html');
exit ();
But I want the new page to open in _top location, not inside the same IFRAME that I use. How can I tell the browser to open the new page in _top not inside the IFRAME?
Thanks in advance.
You are not able to achieve the desired effect in PHP. This is something you'd have to do from JavaScript or add target attribute to <form>:
<form ... target="_top">
You can use javascript to access the parent. You could echo out javascript in your PHP.. so your parent page has this:
function changeURL( url ) {
document.location = url;
}
and in your php script, you echo
<script>
parent.changeURL('mypage2.html' );
</script>
The reason you can't call parent.document.location is because it's read only - you have to have a function available on the parent to do it.
A simple way directly in PHP to redirect the parent page rather than the iframe:
echo "<script>top.window.location = '/mynewpage.php'</script>";
die;
The die; isn't necessarily necessary, but it is good "just in case" to prevent the script from continuing any further, for example, if javascript is disabled in the user's browser.
we can use javascript like this :
target.window.location='locationpage.html';
top.window.location='mypage2.html';
The best and simplest thing to do is to use the form target element
<form action="..." target="_top">
<form action="..." target="_parent">
either of the target parameters works fine
You can either link to the page using Break Out or use code
<?php header("Location: pagename.php?Break=Y"); ?>
You then use the following code in the header of the page with
if(isset($_GET['Break'])) //
{
$BreakFrame = true;
$BreakToPage = "pagename.php";
}
<script language="JavaScript" type="text/javascript">
function changeURL( url ) {
document.location = url;
}
</script>
<?php if($BreakFrame) { ?>
<script language="JavaScript" type="text/javascript">
parent.changeURL('<?=$BreakToPage?>' );
</script>
<? }?>
In the page that you want to load in _top, add the follow code in the header
<script type="text/javascript">
if (top != self) top.location.href = location.href;
</script>
For CakePHP 4, to redirect your parent page just add option 'target'=>'_top' in your iframe's link:
Example:
<?= $this->Html->link(__('Redirect Parent'), ['controller' => 'Users', 'action' => 'view'], ['target'=>'_top']) ?>
All the best!
You can add multiple headers to your redirect.
I use a little function that I created with this in mind.
public function redirect($url){
header('Window-target: _top');
header('Location:' . $url, true, 303);
exit();
}
How can I redirect to another URL in a web page using JavaScript?
window.location.href = "URL2"
inside a JS block on the page or in an included file; that's assuming you really want to do it on the client. Usually, the server sends the redirect via a 300-series response.
Since you tagged the question with javascript and html...
For a purely HTML solution, you can use a meta tag in the header to "refresh" the page, specifying a different URL:
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/somepage.html">
If you can/want to use JavaScript, you can set the location.href of the window:
<script type="text/javascript">
window.location.href = "http://www.yourdomain.com/somepage.html";
</script>
You can redirect anything or more URL via javascript, Just simple window.location.href with if else
Use this code,
<script>
if(window.location.href == 'old_url')
{
window.location.href="new_url";
}
//Another url redirect
if(window.location.href == 'old_url2')
{
window.location.href="new_url2";
}
</script>
You can redirect many URL's by this procedure. Thanks.
If you want to redirect, just use window.location. Like so:
window.location = "http://www.redirectedsite.com"
Why javascript?
http://www.instant-web-site-tools.com/html-redirect.html
<html>
<meta http-equiv="REFRESH" content="0;url=http://www.URL2.com">
</html>
Unless I'm missunderstanding...
location.href = "Pagename.html";
you can also use a meta tag to redirect to another url.
<meta http-equiv="refresh" content="2;url=http://webdesign.about.com/">
http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm
a page directs users back to a page automatically
<meta http-equiv="refresh" content="1; URL=http://localhost/mywebsite/Untitled9.php">
when it reaches 'Untitled9.php' i want it to display an alert box saying 'Message sucessfully posted'
I only want it to display when it id directed back to the page and not when first load
e.g Home - Message page = No alert
Home - message page - submit - redirect to message page = alert 'post sucessfully posted'
Can't control the DOM of a page externally.
What you could do however is pass a variable in the query string to the page you're redirecting to like this
Untitled9.php?message=success
Then on your new page have
<?php
session_start();
if ($_GET['message'] == "success" && $_SESSION['revisit'] == "0")
{
$_SESSION['revisit'] = "1";
?>
<script type="text/javascript">window.alert('Message successfully posted.');</script>
<?php
}
?>
In your first page change your code to look like this
<?php
session_start();
$_SESSION['revisit'] = "0";
?>
<meta http-equiv="refresh" content="1; URL=http://localhost/mywebsite/Untitled9.php">
If I understand your question correctly, this should work for you (assuming you alter the keys for the $_POST variables accordingly, of course):
<?php (isset($_POST['my_sub_btn'])): ?>
<script type="text/javascript">window.alert('Message successfully posted.');</script>
<?php endif ?>
Assuming you're submitting the message from a form, there should be no reason to redirect using a HTML redirect. Set the action attribute of your form to Untitled9.php and it will handle the rest...
Given your requirements, why not set a parameter on succes? Such as:
<meta http-equiv="refresh" content="1; URL=http://localhost/mywebsite/Untitled9.php?success=1">