// Read Get cerruncy from URL request
if(in_array("crncy",$get_page_all)) {
$crnc_set = explode("/crncy/",$open_page);
$crnc = $crnc_set[1];
$get_crnc = (string) $crnc;
$_SESSION['xxxc'] = $get_crnc;
}
if($_SESSION['xxxc']){
echo $_SESSION['xxxc'];
}
else {echo 'Noooooooooo';}
My problem: In next refresh $_SESSION['xxxc'] value gets changed.
Use session_start(); at top of the page.
Related
I'm processing some data from external pages. The pages can be accessed sequentially, i.e http://localhost/info/1.html, http://localhost/info/2.html, http://localhost/info/3.html, ....
<?php
$id = 0;
$id = intval($_GET['id'])+1;
$url = 'http://localhost/info/'.$id.'.html';
if (!$html = #file_get_contents($url)) {
$url = 'http://localhost/crawler.php?id='.$id;
//header("Location: ".$url);
echo '<html><script>window.location.href = "'.$url.'";</script> </html>';
die();
}
//process data
$url = 'http://localhost/crawler.php?id='.$id;
//header("Location: ".$url);
echo '<html><script>window.location.href = "'.$url.'";</script></html>';
die();
?>
The problem is the PHP redirect stops showing error the page is not redirecting properly, and redirect using JavaScript looks like slower. Already tried using header with removing the echo.
**
Is there any way to speed up the process ?
**
My logout.php file is like this. Is there any mistake in my code
logout.php
<?php
session_start();
session_destroy();
header('Location:index.php');
exit;
?>
Here is my index.php file. If I am set $_SESSION['s_activId'] then it is working properly but when I am trying to put condition if $_SESSION['s_activId'] is not set at that time I want to pass header on index page sometimes it works sometimes it does not work.
<?php
include('include/config.inc.php');
if(!isset($_SESSION['s_activId']))
{
$_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
header("Location:index.php");
}
else
{
$wrong = '';
if(isset($_POST['submit']))
{
$checkLogin = "SELECT userName,password,userType
FROM user
WHERE BINARY userName = '".$_POST['userName']."'
AND BINARY password = '".$_REQUEST['password']."'";
$checkLoginresult = mysql_query($checkLogin);
if($userLoginRow = mysql_fetch_array($checkLoginresult))
{
$_SESSION['s_activId'] = $userLoginRow['userName'];
$_SESSION['s_password'] = $userLoginRow['password'];
$_SESSION['hg_userType'] = $userLoginRow['userType'];
if(!$_SESSION['s_urlRedirectDir'])
{
header("Location:index.php");
}
else
{
header("Location:reminder.php");
}
}
else
{
$wrong = "UserId And Password Is Not Valid";
}
}
}
include("bottom.php");
$smarty->assign('wrong',$wrong);
$smarty->display("index.tpl");
?>
The problem arise in the condition below in index.php:
if(!isset($_SESSION['s_activId']))
{
$_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
header("Location:index.php");
}
When you logout, you are calling session_destroy() on logout.php and redirecting on index.php and the condition above gets true as s_activId is not set in session and again you are redirecting on index.php (without setting s_activId in session). The above condition will be true until the variable s_activId set in session and because of this you are getting ERR_TOO_MANY_REDIRECTS error.
The solution is, on index.php set the variable s_activId in session before calling the header method. Refer the code below:
if(!isset($_SESSION['s_activId']))
{
$_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
$_SESSION['s_activId'] = true;
header("Location:index.php");
}
Dont redirect index.php to index.php. you having redirects loop. Also
if you have code below that also can fire add die in if because after
redirect code below still executes. I didnt read your code, maybe
there isnt problems with this but after
header("Location: lalala"); always add die(); or exit();
how to jump a page if condition true and also i want to sent a variable value to secont page
if(isset($_POST['compair']))
{
$_SESSION['usermail'];
$answer=$_POST['answer'];
if ($answer == $_SESSION['answer'])
{
$mail=$_SESSION['usermail'];(i want to sent "$mail" variable)
header("Location:resetpass.php?value = $mail ");
}
else
{
echo "<script>alert('Please Try again')</script>";
}
}
please also tell me how to receive this variable on second page.
Your solution is correct. Just pay attention to spaces:
header("Location: resetpass.php?value=$mail");
exit; // as suggested by "nogad"
Also make sure that resetpass.php file is in the same directory of current page.
In resetpass.php you can get the variable by $_GET['value'] like:
<?php
if( isset($_GET['value']) ){
$mail = $_GET['value'];
}
After header("Location : resetpass.php?value=$mail");
exit(); // i.e quit the current page and go to resetpass.php
Then at resetpass.php collect $mail using the GET method.
if(isset[$_GET['value'])){
$the_mail = $_GET['value'];
}
I am writing from my handy. So apologies for any layout discripancies
I'm develop a hybrid application and it will using PHP sessions to save user information. In my case, I tried to used php sessions to save the data, but it doesn't save. And then, to testing in web, the result var is show saved.
Here is my example:
<?php
session_start();
if(isset($_POST["Token"])){
$token = $_POST["Token"];
if (isset($_SESSION['device_token']) && $_SESSION['device_token']) {
$token = $_SESSION['device_token'];
} else {
$_SESSION['device_token'] = "notoken";
}
}
?>
Here is my PHP info:
My php Info 1
My php Info 2
Edit:
<?php
ini_set('session.save_path',$_SERVER['DOCUMENT_ROOT'] .'/phpVar');
session_start();
if(isset($_POST["Token"])){
$token = $_POST["Token"];
$_SESSION['device_token'] = $token;
}
if(isset($_GET['ID'])){
$token = $_SESSION['device_token'];
$member_id = $_GET['ID'];
$_SESSION['ID'] = $member_id;
echo $_SESSION['device_token'] ;
echo $_SESSION['ID'] ;
}
?>
because you missed the }
so, instead of:
if(isset($_POST["Token"])){
$token = $_POST["Token"];
should be:
if(isset($_POST["Token"])){
$token = $_POST["Token"];
}
EDIT
Ok, then try to see whether you session directory is writable:
if (!is_writable(session_save_path())) {
echo "No, it's not. Path:".session_save_path();
}
else{
echo "yes, it's writable";
}
EDIT
when path is not set, you might set it manually just before session_start
ini_set('session.save_path',getcwd(). '/tmp');
and afterwards you need to create tmp folder and give it right permission
I am trying to display random banner each time the user refresh the page. The problem I am facing is that I don't want the last banner to be displayed again. I there any other way to remember the last displayed one without using cookies or database implementation?
Cookie Implementation:
<?php
$randIndex = rand(1,6);
if(!isset($_COOKIE["lastDispalyed"])){
setcookie("lastDispalyed",$randIndex,time()+60*60*24);
}
else{
while($_COOKIE["lastDispalyed"] == $randIndex){
$randIndex = rand(1,6);
}
setcookie("lastDispalyed",$randIndex,time()+60*60*24);
} ?>
<img src="images/mainBanners/<?php echo $randIndex; ?>.JPG"/>
You could use a session variable:
<?php
session_start(); // <-- start session before outputting any HTML
$randIndex = rand(1,6);
if (!isset($_SESSION["lastDisplayed"])) {
$_SESSION["lastDisplayed"] = $randIndex;
} else {
while ($_SESSION["lastDisplayed"] == $randIndex) {
$randIndex = rand(1,6);
}
$_SESSION["lastDisplayed"] = $randIndex;
}
?>
Reference session_start().
Set up a session variable for the id or url of the banner:
$_SESSION['lastDisplayed'] = $id; //could be the id of the banner you are displaying, or the file's url, whatever you have access too
And then test for it when you go to display a new banner.