Jump to content

can visits multiplied in PHP SESSION


turk

Recommended Posts

hi fellas. my first ever question on phpfreaks.

 

when visitors type www.mydomain.com, session takes them to www.mydomain.com/landingpage.php

when they click "go to the site" on www.mydomain.com/landingpage.php,  it takes them to the index page www.mydomain.com

 

Unless they clean their cooking, session won't forward take visitors to the landingpage ever again.

but is there anyway to show the landing page to visitors, lets say the first 5 times when they type www.mydomain.com?

 

 

here is what i exactly use for it.

 

<?php
session_start();

if(!isset($_SESSION['views']) || !$_SESSION['views'])
{
$_SESSION['views'] = 1;
header("location: /landingpage.php");
exit;
}
?>

 

 

Much Thanks in advance. Turk.

Link to comment
Share on other sites

<?php
session_start();

// default the variable to avoid a notice error:
$_SESSION['views'] = !empty($_SESSION['views'])?$_SESSION['views']:0;

if ($_SESSION['views'] < 5)
{
$_SESSION['views'] += 1;
header("location: /landingpage.php");
exit;
}
?>

 

Should do it.

Link to comment
Share on other sites

This would be more suitable, so you dont badger the visitor too much in quick concession.

 

<?php
session_start();

//-- times before landing page is disabled
$lpcount = 5;

//-- time between landing page shows 
$halt_time = 60 * 10; //10 minutes

// default the variable to avoid a notice error:
$_SESSION['views'] = !empty($_SESSION['views'])?$_SESSION['views']:0;

$_SESSION['last_land'] = (int)$_SESSION['last_land'] > 0 ? $_SESSION['last_land'] : 0;

if ($_SESSION['views'] < $lpcount && $_SESSION['last_land'] < (time() - $halt_time))
{
$_SESSION['views'] += 1;
$_SESSION['last_land'] = time();
header("location: /landingpage.php");
exit;
}
?>

 

However if you just want to stop the loop then add a check in the IF() that says "if http_refferer is my own site, then do not redirect to landing page"

 

 

Link to comment
Share on other sites

it brings the .com/landingpage.php without showing /index.php 5 times.

 

I am having a real problem with reading shit today:

 

<?php
session_start();

// default the variable to avoid a notice error:
$_SESSION['views'] = !empty($_SESSION['views'])?$_SESSION['views']++:0;

if ($_SESSION['views'] > 4)
{
header("location: /landingpage.php");
exit;
}
?>

 

That should do what you want...hopefully.  :)

Link to comment
Share on other sites

WOW. first of all very impressed by all these help.

u guys are fucking great. I love the freaks already.

 

 

@djless

 

clever. i really like the clock. i dont know why but it works as my session code. it wont do the count. :/

 

 

@premiso

 

this session did not redirect me to landingpage.php for some reason

 

 

 

are you saying that you want the first 5 views of a user to be directed to your index, then the rest to be redirected, or something else..?

 

yes. when users type the root domain, instead of index.php, i want visitors to be directed /landingpage.php at least 5 times.

 

Link to comment
Share on other sites

premiso's code should do what you need it to do, with a slight adjustment.

 

<?php
session_start();

// default the variable to avoid a notice error:
$_SESSION['views'] = (!empty($_SESSION['views'])) ? $_SESSION['views']++ : 0;

if ($_SESSION['views'] > 4)
{
header("Location: landingpage.php");
exit;
}
?>

 

 

Link to comment
Share on other sites

very tough. it is printing only

Array ( [views] => 0 )  

 

i might be wrong but it seemed to me like, it gets directed to landingpage.php but before even load it get redirected to back to index.php

Link to comment
Share on other sites

okay we are going to do it the if else way

 

<?php
session_start();

// default the variable to avoid a notice error:
if(empty($_SESSION['views'])){
      $_SESSION['views'] = 0;
}else{
      $_SESSION['views'] = $_SESSION['views'] + 1;
} 

if ($_SESSION['views'] > 4)
{
header("Location: landingpage.php");
exit;
}
?>

 

pretty much the same thing here, not sure why the ternary would't work so i want to make sure something funky isn't happening

Link to comment
Share on other sites

sorry for the headache im causing AyKay47.

why simple looking things always has to cause the major headache.

 

no luck with the if statement either chief. getting the same print "Array ( [views] => 0"

 

 

 

Link to comment
Share on other sites

thank you david and tendola.

 

updated the session as follows, and now it only stays on the /landingpage.php

 

<?php
session_start();

$_SESSION['views'] = (isset($_SESSION['views'])) ? $_SESSION['views']++ : 0;
if ($_SESSION['views'] <= 4)
{
header("Location: landingpage.php");
exit;
}
?>

 

 

P.S. glad asked you guys, this much testing would have taken me over a week.

Link to comment
Share on other sites

Just to make sure you know - unless you have explicitly told PHP to keep sessions going beyond a browser close or a short period of time - this won't keep the value after the use closes their browser.

 

The next time they visit your site they'll be taken to landingpage.php another 5 times automatically.

 

A cookie would be better if you wanted to hold that count beyond a single browser session.

Link to comment
Share on other sites

i want users to be taken to the landingpage.php each time when they visit the site for the next 5 times they visit the site.

 

the existing code i previously had (which is down below) works like a charm but brings the landingpage.php only once.

 

<?php
session_start();

if(!isset($_SESSION['views']) || !$_SESSION['views'])
{
$_SESSION['views'] = 1;
header("location: /landingpage.php");
exit;
}
?>

 

 

here it goes in this code.

 

 

user types www.mydomain.com and get redirected to www.mydomain.com/landingpage.php where clicks on HOME (<a href="www.mydomain.com">) button and goes to www.mydomain.com

closes to browser, and next day user types www.mydomain.com and gets directed to www.mydomain.com

 

 

what i need is that users redirected to the /landingpage.php at least the first 5 times they visit the site.

 

 

P.S. i hope, i made more sense this time. this could be very strategic and useful to capture user emails, advertise promotional, recent news, info video, etc. user gets fully familiar with the site.

Link to comment
Share on other sites

xyph brings up a good point which I have overlooked. Lets say that you got the code to work with sessions, an the user visits your site 6 times without closing the browser and the 6th time they are taken to the homepage or wherever you are directing them. When the user closes the browser and reopens, the session information will be erased, thus the session value will be reset to 0, starting your count all over again. I doubt that this is your desired intentions, perhaps you should use cookies for this instead and overwrite the cookie value each time a user visits the page...

Link to comment
Share on other sites

the best option would be to use the http referer. that way they dont get annoyed browsing your site but if they type it in the url then they get redirected. Put this in a core file thats included everytime and no matter what url they type in they will be redirected to the landing page by default. Put it only on the index page and it will only redirect to landing page if index is visted from somewhere other than your own site.

 

Which ever one is more in line with your site i guess, ive used both ways in the past.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.