I have a website that used to be only a news page, but as we grown, I had to move the news section from homepage to domainname.com/news
To not confuse our loyal users when they landing on the new home page, I would like to give them an option (light box). The first time when you arrive to the homepage, you get a message, if you want to go directly to News and keep it as a default (or cancel). If you choose yes, next time you type our domain name, it will take you to the news section.
I hope there is a javascript that could do this job.
Use JavaScript to do an alert confirm() to find out what the user wants to do. From that set a cookie.
Next load, have PHP check the cookie to find out where to head to.
function checkCookie()
{
var wellcome=getCookie("firstime");
if (wellcome!==null && wellcome!=="")
{
alert("Welcome");
}
else
{
alert("is your first time");
setCookie("firstime",true,365);
}
}
Related
I want to change the landings page if i click on a button or link
So for example I have two pages: page-1 and page-2.
If i click on link-2 the default landings page get changed from page-1 to page-2 and if I click on link-1 the default landings page get changed from page-2 to page-1.
If i leave the website and come back i want that the default landings page is still the same as it was set last time.
This can be easily done by setting a cookie like this:
<?php
if($_GET['landingpage']) setcookie("landingpage", $_GET['landingpage'], time()+3600);
if($_COOKIE["landingpage"] == 1) {
echo "landingpage 1";
}
if($_COOKIE["landingpage"] == 2) {
echo "landingpage 2";
}
if(!$_COOKIE["landingpage"]) echo "default page";
?>
landingpage1
landingpage2
Check https://www.php.net/manual/en/function.setcookie.php for more info on expiration, etc.
Also beware: Not all users allow setting cookies.
If you have a PHP server that can store data (I'm assuming this because of the PHP tag), then you would handle it like this:
When the user hits your landing page, pull their landing page preference from your PHP data store and use that to determine what page they hit.
If the user clicks your link, you need to send that information back to the PHP server so that it can store their preferences, likely via an API call.
This is very high level, because both of these tasks tend to have a lot of different ways. I'd recommend trying to make this work, then asking specific questions if you get stuck.
I am working on a simple website that requires users to enter information in order over 3 different pages. So they need to go from page A to B to C. How can I stop them from typing in www.example.com/pageB.php, which skips page A?
Also, I'm not even sure what you call pages that must be visited in order, so any suggestions for google search terms on this also appreciated.
You can store vars in session to check whether the user has visited previous pages.
page1.php
<?php
$_SESSION['has_visited_page1'] = true;
....
page2.php
<?php
if (empty($_SESSION['has_visited_page1'])) {
exit('You must visit page 1 first');
}
If it's a form, you can store in session the field values from previous page.
you can check page refer info if the page refer not your expected then redirect it or show something you wanted
edited1
in PHP, you can try the code in your pages
var_dump(#$_SERVER["HTTP_REFERER"])
you'll know how to write it.
I have different pages and scripts on my website. I want to show 1 URL in the adressbar for all the pages.
I have pages like:
www.example.com/index.php
www.example.com/map1/index.php
www.example.com/map1/map2/index.php
www.example.com/map1/map2/map3/index.php
I want that all these URLS should be shown like:
www.example.com
I have expirimented with my .htaccess script, but I cant get this working.
Can anybody help me with this problem? How can I show all the URL`s on my page like "www.example.com".
You could make www.example.com/index.php (which would be the default for www.example.com) be the only page that actually gets loaded fully, with all the others simply providing content to be loaded via ajax.
You could also make www.example.com/index.php contain only an iFrame or a frameset, such that clicks to other locations would only be to the nested frame, leaving the address bar always at www.example.com
You could also try taking "map1" and "map2" etc out of the URL and use them instead as post variables, or $_SESSION variables, or what have you.
Hide the Target URL of a Link in Status Bar
There are some instances where you have redirect the user through one page to get them to another page. There is a way to do this stealthily - without letting the user know that there was a redirect. Yes - it sounds evil - but it don't have to be. Say you have a click tracking software - you have to track each click the users make. To do that you need a redirecting page what will track the clicks. Hopefully, the following illustration will make things clearer...
Current Page->Page with the click counter->Destination Page
You don't want the user to see that you are passing through the middle page. Usually, the URL will flash in the address bar for just a second(or less) - so we don't have to worry about that. We just have to prevent the URL from appearing in the status bar when the user hovers over the link.
There are three methods to do this...
Change the status text
Hijack and stop the click event and redirect
page.
Make an Ajax call on click event.
Changing Status Text
This is the old method. This uses the window.status property to show a different URL to the user. Simple and easy method - but it rarely works now a days. This method has been abused by malicious sites a lot - so most browsers have disable this option. In Firefox, you can find that option at Tools -> Preferences -> Content -> Enable Javascript(click on the 'Advanced' Button) -> Change status bar text. If that's checked, you can use window.status to change the status bar text. But its disabled by default.
But if you still want to use this method(not recommended), this is how to do it...
<a href="click_counter.php?redirect_to=http://www.google.com/"
onmouseover="window.status='http://www.google.com/';return true;"
onmouseout="window.status='';">Go To Google</a>
Hijacking Click Event
In this method, when the user clicks on the link, the script captures the click event and stops it. This will prevent the browser from opening up the target page. Then we use location.href to go to the new page. Sample code below...
HTML Code
Go To Google
Javascript Code
<script type="text/javascript">
function init() {
document.getElementById("google-link").onclick=function(e) {
e=e||window.event;
stopEvent(e);
location.href="click_counter.php?redirect_to=http://www.google.com/";
return false;
}
}
window.onload=init;
</script>
Ajax Method
This is for all you web 2.0 fans. Ajax method simply makes a call to the counter server side script on the click event. This is perhaps the best method of all - as the counter URL doesn't appear at all. Needless to say, the server side script used here will be different from the one used in the other methods - there is no redirection here. The code is very simple as well...
HTML Code
Go To Google
**Javascript Code**
<script type="text/javascript">
function init() {
document.getElementById("google-link").onclick=function(e) {
jx("counter.php?url="+escape("http://www.google.com/")); //Use your favorite ajax library here.
}
}
window.onload=init;
</script>
I want to create a pop up in the home page of my site when each time a new visitor visits the site. I have the pop up window. The problem is whenever I hit on home page it comes. I want it to display only once in the home page not each time I click for home page during the visit to the site. If the browser is closed or the session is out, it pop-up coming is fine.
Any suggestions highly appreciated.
What about 'is_new_visitor' of Visitor data:
$visitorData = Mage::getSingleton('core/session')->getVisitorData();
Locally it is not resulting any values? Any other suggestions!!!!!!!
the easiest approach would be to set the session variable directly in your pop-up block (if you have the Block layer for it). It needs to be set after the block is actually displayed (so it will be displayed the 1st time) - for example in the block destructor:
public function __destruct() {
Mage::getSingleton('core/session')->setOldVisitor(true);
}
Then before you show the pop-up add the case:
if (!Mage::getSingleton('core/session')->getOldVisitor()) {
//do your thing here
}
this is a little bit tricky.
usually when someone clicks on a link that requires him to register, this person will be redirected to the registration page and then back to the last visited page. this is possible cause the link sent a GET key through the url to the registration.php which uses the key to go back to last visited page.
but i intend to use jquery ajax for registration. basically ive got 3 different php pages. all of them include the same header.php. and in header.php ive got a registration button which i have id tagged. when this button is clicked ( $(#registration_button).click()... ) jquery will show a box (a div that was hidden in the center of the browser) with registration information. then he will register and i will redirect him to the last visited page, that is to say the current one he sees. i have to refresh the php-page to be able to show all links that a registered user can see, thats why i have to use window.location.href.
now to the question. how do i let jquery know which page is the current one he is visiting? ive got 3 php-pages.
if there is something you dont understand, please free to ask.
or if you got suggestions of other solutions, let me know. but i really want to display the registration box right away without redirecting him to another page.
You can set cookies initially in php and then update/read them via js.
You could assign the page to a session and do it that way.
$_SESSION["page_visited"] = "x.php";
Make sure to use session_start on the pages using sessions. Then just redirect to the relevant page.
header('Location: http://www.example.com/'$_SESSION["page_visited"]);
I did a similar thing not two weeks ago, correct me if I'm wrong, but if you want the registration to direct to the page the user was on, after the user has been registered in the ajax just add:
window.location.href=window.location.href;
That way the after the registration is done, it just reloads where the member was with the environment of a logged in user. This method worked great for me.