Session variable is not displayed online but displayed locally - php

In the bellow code i have printed a session variable on the output page
<?php ob_start();
session_start();
include("database.php");
include("tracking-header.php");
?>
<div class="dt-content" style="text-align:center;">
<p class="srymsg">Sorry</p>
<p class="srymsg2" style="margin-bottom:110px;">The Vehicle number <span style="color:#000; font-weight:bold; text-transform:uppercase;"><?php print $_SESSION['vehicleno']; ?></span>, not found.<br />please try again.</p>
</div>
<div class="nxtbtn" >
<input type="button" value="BACK" name="back" style="float:left;margin:17px 25px 16px;" />
<?php include("tracking-footer.php");?>
in this print $_SESSION['vehicleno']; is displayed on local but when i upload this file online and then this is not displayed on the page. can any one say what is the problem in it?

Try by switching place of ob_start and session_start function like below
<?php
session_start();
ob_start();
include("database.php");
include("tracking-header.php");
?>
<div class="dt-content" style="text-align:center;">
<p class="srymsg">Sorry</p>
<p class="srymsg2" style="margin-bottom:110px;">The Vehicle number <span style="color:#000; font-weight:bold; text-transform:uppercase;"><?php print $_SESSION['vehicleno']; ?></span>, not found.<br />please try again.</p>
</div>
<div class="nxtbtn" >
<input type="button" value="BACK" name="back" style="float:left;margin:17px 25px 16px;" />
<?php include("tracking-footer.php");?>

Related

Get textarea data. [Froala Editor] [Codeigniter]

I try to get data from text area,When submit form.
<?php
echo form_open_multipart('start/create','class="build_form"');
...
echo form_textarea('proDetail','','id="proDetail"');
...
echo form_submit('submit','Save','class="btn btn-primary"');
echo form_close();
?>
Try to show data in this function.
public function create()
{
echo print_r($this->input->post('proDetail'));
}
It give me a data from textarea, But it's not same when look in textarea.
How it look in textarea.
This is code in textarea.
<p><img class="fr-draggable fr-fir fr-dii" style="width: 300px;" src="http://localhost/siamfunding/img/users/upload/3a5e29ad7b5c64b16a97c56ce2a006cb7f66c7e3.jpg"></p>
<h1 style="text-align: center;">
<strong>asdasddadasdddd</strong>
</h1>
<p style="margin-left: 20px;">qwdqwdasdasasdwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</p>
<p style="">daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas</p>
<p style="">dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd</p>
<p style="">aaaaaaaaaaaaaaaad</p>
And, This is how it look when i try to show data.
This is code.
<p>
<img class="fr-draggable fr-fir fr-dii" xss="removed" src="http://localhost/siamfunding/img/users/upload/3a5e29ad7b5c64b16a97c56ce2a006cb7f66c7e3.jpg">
</p>
<h1 xss="removed">
<strong>asdasddadasdddd</strong>
</h1>
<p xss="removed">qwdqwdasdasasdwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</p>
<p xss="removed">daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas</p>
<p xss="removed">dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd</p>
<p xss="removed">aaaaaaaaaaaaaaaad</p>
<p xss="removed">
<br>
</p>
What happen, How can i make it look like in text area.
Ps.I try to import css and Jquery in page. It's not work.

PHP registration form: Make the inputs with red borders if there is an error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm making a registration form with PHP and I'd like to do something: if user has not completed the form correctly, I want, in addition to the error message, make the inputs (where there is an error) with red borders.
My registration form (HTML part):
<?php if(!empty($errors)): ?>
<div class="flash-message error">
<h3>You have not completed the form correctly. The error(s) come(s) from the following thing(s):</h3>
<ol>
<?php foreach($errors as $error): ?>
<li>
<p><?= $error; ?></p>
</li>
<?php endforeach; ?>
</ol>
</div>
<?php endif; ?>
<h1 class="page-heading"><?php echo $title; ?></h1>
<form action="" method="post">
<ul>
<li>
<label for="nickname">Nickname:</label> <input id="nickname" name="nickname" type="text">
<p class="input-description">Your nickname will be as an identity on the site; it will be displayed wherever you will post, etc.</p>
</li>
<li>
<label for="email">Email:</label> <input id="email" name="email" type="text" placeholder="your#email.com">
<p class="input-description">Enter a valid email to receive the confirmation link to validate your account.</p>
</li>
<li>
<label for="password">Password:</label> <input id="password" name="password" type="password">
<p class="input-description">Enter a password to sign in to your account. Try to put a difficult password to make it more complicated to find.</p>
</li>
<li>
<label for="password-confirmation">Password Confirmation:</label> <input id="password-confirmation" name="password-confirmation" type="password">
<p class="input-description">Confirm the password that you have put in the field above.</p>
</li>
</ul>
<button type="submit" class="button primary">Sign Up</button>
</form>
Current result: http://prntscr.com/86h5r2
PHP code:
<?php
if(!empty($_POST))
{
/* Nickname */
if(empty($_POST["nickname"]))
{
$errors["nickname"] = "You have not completed the nickname field.";
}
elseif(!preg_match("/^[a-zA-Z0-9 _]+$/", $_POST["nickname"]))
{
$errors["nickname"] = "Your nickname is not valid.";
}
/* E-mail */
if(empty($_POST["email"]))
{
$errors["email"] = "You have not completed the email field.";
}
elseif(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
{
$errors["email"] = "Your email is not valid.";
}
/* Password */
if(empty($_POST["password"]))
{
$errors["password"] = "You have not completed the two password fields.";
}
elseif($_POST["password"] != $_POST["password-confirmation"])
{
$errors["password"] = "The passwords did not match. Please enter the same password in both fields.";
}
}
?>
to add a border to the input with error you would want to embed a php if statement like this in the class attributes. just define classname in your css
<input type="text" class="<?= isset($error['name']) ? 'has-error' : '' ?>" value="" >
Adding a style to the <li> is one way
<ol>
<?php foreach($errors as $error): ?>
<li style="border:red solid 1px">
<p><?= $error; ?></p>
</li>
<?php endforeach; ?>
</ol>
A better way would be to create some css and then just add a class to your <li>
<style>
.an-error-msg {
border:red solid 1px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px; /* future proofing */
-khtml-border-radius: 10px; /* for old Konqueror browsers */
}
</style>
<ol>
<?php foreach($errors as $error): ?>
<li class="an-error-msg">
<p><?= $error; ?></p>
</li>
<?php endforeach; ?>
</ol>
Why not just make it client side with the required attribute like this: https://jsfiddle.net/kn7qjg6c/
HTML
<form method="post">
<input type="text" placeholder="name" required/>
<input type="submit" />
</form>
CSS
input:required:focus {
border: 1px solid red;
outline: none;
}

Redirect if page is blank

I'm working on some sort of search engine that adds on to a URL to complete the request. using header(Location:http://www.WEBSITENAME.com/'. $search); Although sometimes this will send me to a blank page. Was wondering if there's any sort of code that will redirect me to another page if that error happens. I want the else to be what it redirects to if the page is blank. Thanks.
My code:
search.php
<?php
$search = $_POST["search"];
if(isset($_POST['search'])){
header('Location:http://cydia.saurik.com/package/'.$search);
}else{
?>
<?php
echo "
<head>
<style>
#header{
color:black;
}
.header{
color:black;
font-size:25px;
}
#header_minor{
margin-top:20px;
}
.header_minor{
font-size:18px;
}
a[class='header_minor']{
color:black;
}
body{
text-align:center;
margin-top:14%;
}
#idea{
margin-top:20px;
}
.hidden{
display:none;
visibility:hidden;
}
</style>
</head>
";
?>
<div id="header">
<span class="header">
Sorry, this tweak was not found...
</span>
</div>
<div id="header_minor">
<span class="header_minor">
Would you like to suggest it? or Return home
</span>
</div>
<div id="idea">
<form method="POST" action="idea.php" name="idea">
<input type="text" name="idea" value="<?php echo $_POST['search']; ?>"/>
<input type="text" name="hidden" class="hidden"/>
<input type="submit" value="Submit"/>
</form>
</div>
<?php
exit();
}
?>
It could have been better if you can call an api on that site so that you can interact easier with the external site.
I would do something like this:
PHP:
<?php
if(isset($_POST['search'])) {
$search_text = $_POST['search_field'];
$location_url = "http://cydia.saurik.com/package/{$search_text}/";
$content = #file_get_contents($location_url); // use this function to query on site
if($content) {
// redirect if it has a result
header("Location: {$location_url}");
} else {
// will go here if query on external site is empty (blank)
// create your own empty result page that says your search yielded no results (your own page, redirect the user)
// sample
header("Location: http://www.yoursite.com/index.php?noresults=1");
}
}
?>
HTML:
<form method="POST" action="index.php">
<input type="text" name="search_field" class="" id="" /><br/>
<input type="submit" name="search" class="" id="" value="Search" />
</form>
<?php if(isset($_GET['noresults'])): ?>
<div class="yourdesign" style="display: block; width: 300px; border: 1px solid black;";>
<h1>No results found</h1>
</div>
<?php endif; ?>

JqueryMobile 1.4.0 pass parameter to popup

I'm pretty new to jQuery Mobile and PHP and I'm having an issue where I have a PHP while loop
while ( $row = sasql_fetch_array ( $idresult ) ) {
echo "
<li>
<a href='#' data-rel='popup' data-position-to='window' data-transition='pop'>
<div class='ui-grid-a'>
<div class='ui-block-a'>
<div class='ui-bar ui-bar-a titleRow' style='height:15px'>Identification Type</div>
<div id='idType' class='ui-bar ui-bar-a 'style='height:15px; background-color:transparent; border: none; color: black; font-weight: normal;' >" . $row ['description'] . "</div>
</div>
<div class='ui-block-b'>
<div class='ui-bar ui-bar-a titleRow' style='height:15px'>Details</div>
<div id='idNo' class='ui-bar ui-bar-a ' style='height:15px; background-color:transparent; border: none; color: black; font-weight: normal;'>" . $row ['number'] . "</div>
</div>
</div>
</a>
<a href='#editCustId' data-rel='popup' data-position-to='window' data-transition='pop'>Edit</a>
</li>
";
} // end while
echo "</ul>";
} // end if
When the use clicks on the edit button I need to pass the ID of that particular row. I'm not sure where I should put this in but it could be something like this...? Will this work when there is no form?
<input type="hidden" name="the_id" value='<?php " . $row ['theid'] . " ?>' />
However I can't figure out how to do this. I have tried opening the dialog as a new page ie.
<a href='./editCustId.php?id=" . $row['theid'] . "' data-rel='popup' data-position-to='window' data-transition='pop' class='ui-btn ui-btn-inline ui-icon-edit ui-btn-icon-notext'>Edit</a>
When edit is clicked this popup will open
<div data-role='popup' id='editCustId' data-theme='a' data-overlay-theme='a' data-dismissible='false' style='min-width: 300px;'>
<div data-role='header' data-theme='a'>
<h1>Add ID</h1>
</div>
<div data-role='main' class='ui-content'>
<form id='editId' onsubmit="return false;">
<input type="hidden" name="cust_id" value='<?php echo $custid; ?>' />
<input type="hidden" name="sess_id" value='<?php echo $sid; ?>' />
<!-- <input type="hidden" name="submitted" value="true" /> -->
<div class="ui-field-contain">
<label for="phoneType">Type</label>
<select name="idType" id="idType">
<?php echo $idInnerOptions; ?>
</select>
</div>
<div class="ui-field-contain">
<label for="idDesc">Description</label> <input type="text" name="idDesc" id="idDesc" value="">
</div>
<div class='ui-grid-a'>
<div class='ui-block-a'>
<input type='submit' id="submit" value='Update' class='ui-btn ui-btn-inline' data-transition='pop' />
</div>
<div class='ui-block-b'>
Cancel
</div>
<div id="success" style="color: black;"></div>
</div>
</form>
</div>
</div>
The description and number will contain the relevant info based on which link was clicked.
I've been looking into passing the data through ajax but I'm not really getting what I should be doing?
I Think there are 2 issues here for you to check more:
As i recall, the popup feature of jquery mobile is for code that are inside divs that has the popup data-role. So, what you tried to do is not in the JQM logic. However, JQM also allows you to use iframe in divs with popup data-role so maybe that will be a good solution for you.
Another way to go, could be to dynamicly load the content of the page you want by AJAX to a div that has the popup data-role.
Hope this helps

How to let the user choose a page number?

I've added information to some boxes, which are alligned with the 'float' attribute.
The content of all those boxes together is too big to fit in the webpage, so I want to put those boxes on different pages, and to let the user choose which page he wants to view.
E.g: Choose page: 1 2 3... (last page)
The contents of these 'pages' must be in divisions.
For reference, see my css code:
.clear {
clear: both;
}
#over-ons .imagebox,
#over-ons .contentbox
{
background-color: #C4C4A6;
float: left;
margin: 0 10px 40px 0;
padding: 10px;
border: 2px solid black;
}
#over-ons .imagebox {
width: 100px;
text-align: center;
}
#over-ons .contentbox {
width: 200px;
}
Also, see my HTML code of the 'boxes' I mentioned:
<div class="imagebox"><img src="media/images/overons/bas.png" /></div>
<div class="contentbox">
Function: blablablabla<br />
Name: blablabla<br />
City: Breda<br />
Education: HBO Informatica<br />
</div>
<div class="clear"></div>
How do I create the ability to let the user view 3 different boxes, depending on the page number he wants to see?
Edit:
My current solution looks like this, only nothing happens when I click 'page 2':
<?php
//Vraag pagina op
$page = 1;
if (isset($_POST['page']) && is_numeric($_POST['page']))
$page = $_POST['page'];
?>
<? if ($page == 1) { ?>
<div class="imagebox"><img src="media/images/overons/pieter.png" /></div>
<div class="contentbox">
Functie: Bedrijfsleider<br />
Naam: Pieter<br />
Stad: Deurne<br />
Opleiding: HBO Informatica<br />
</div>
<div class="clear"></div>
<div class="imagebox"><img src="media/images/overons/patrick.png" /></div>
<div class="contentbox">
Functie: Verkoper<br />
Naam: Patrick<br />
Stad: Roosendaal<br />
Opleiding: HBO Bedrijfskundige Informatica<br />
</div>
<div class="clear"></div>
<div class="imagebox"><img src="media/images/overons/rick.png" /></div>
<div class="contentbox">
Functie: Ontwikkelaar<br />
Naam: Rick Gommers<br />
Stad: Oosterhout<br />
Opleiding: HBO Informatica<br />
</div>
<div class="clear"></div>
<? }
else if ($page == 2) { ?>
<div class="imagebox"><img src="media/images/overons/bas.png" /></div>
<div class="contentbox">
Functie: Salesmanager<br />
Naam: Bas<br />
Stad: Breda<br />
Opleiding: HBO Informatica<br />
</div>
<div class="clear"></div>
<div class="imagebox"><img src="media/images/overons/robbert.png" /></div>
<div class="contentbox">
Functie: Administrateur<br />
Naam: Robbert Tuerlings<br />
Stad: Goirle<br />
Opleiding: HBO Bedrijfskundige Informatica<br />
</div>
<div class="clear"></div>
<div class="imagebox"><img src="media/images/overons/timothee.png" /></div>
<div class="contentbox">
Functie: Implementatie Technicus<br />
Naam: Timothee<br />
Stad: Breda<br />
Opleiding: HBO Informatica<br />
</div>
<div class="clear"></div>
<? }
else { ?>
<div class="contentbox">
You didn't select a proper page!
</div>
<? } ?>
Imagine your current page is called index.php. So first of all you want to create the links to your pages in your HTML as the following:
Page 1
Page 2
Page 3
And for a clear code you can simply put the content of your "boxes" in an array and then output the corresponding entry for the page:
<?php
$content = array{ "Page 1 data", "Page 2 data", "Page 3 data" };
//Fetch the page
$page = 1;
if (isset($_GET['page']) && is_numeric($_GET['page']))
$page = $_GET['page'];
?>
<div class="contentbox">
<? echo $content[($page - 1)]; ?>
</div>
Another solution (less easy to read and to maintain, but easier if your content is really complex) you can simply fetch the page number and in a regular if else display the box they requested.
<?php
//Fetch the page
$page = 1;
if (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0)
$page = $_GET['page'];
?>
<? if ($page == 1) { ?>
<div class="contentbox">
Your first box for page 1
</div>
<? }
else if ($page == 2) { ?>
<div class="contentbox">
Your second box for page 2
</div>
<? }
else if ($page == 3) { ?>
<div class="contentbox">
Your third box for page 3
</div>
<? }
else { ?>
<div class="contentbox">
You didn't select a proper page!
</div>
<? } ?>
But ye, there are 1001 ways to do this. It really depends on your needs and the way you want to do it. The more you hardcode, the uglier the code usually gets.. ;-)
One way is to have all divisions on the page and make only the one visible which user has clicked to...To do so you can make all 3 divs and by default make them hidden and by javascript trigget action...
Another way is by PHP's output buffering to accomplish this:
ob_start(); // begin collecting output
include 'myfile.php';
$result = ob_get_clean(); // retrieve output from myfile.php, stop buffering
$result will then contain the text..
The first method is preety easy one most people use it..But as you specificaly said you have created all separate pages for all 3 div's I had to add the php method..

Categories