TYPO3 userFunc give GET Parameter to php file - php

I am including a php file via userFunc and want to give the get parameter "?session_start=1" and use this in the function.
TS:
includeLibs.voucher = fileadmin/php/shop_init.php
lib.phpscript = USER
lib.phpscript.userFunc = voucher->init
lib.phpscript.session_start_var = GP:session_start
php file
<?php
class voucher {
public function init($content ="", $conf){
$session_start = $conf['session_start_var']?t3lib_div::_GP($conf['session_start_var']):false;
$lang_id = ($GLOBALS['TSFE']->sys_language_uid == 0 ? "&lang=de" : "&lang=en");
if($_GET["session_start"] == "" && $_GET["tx"] == "" && strpos($_SERVER['HTTP_USER_AGENT'], 'Safari')){
if($_GET["type"] == 1)
die(header("Location:http://xx.pro/post?shop=1&s=1&referer=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]$lang_id"));
elseif($_GET["type"] == 2)
die(header("Location:http://xx.pro/post?shop=2&s=1$lang_id"));
elseif($_GET["type"] == 3)
die(header("Location:http://xx.pro/post?shop=3&s=1$lang_id"));
else
die(header("Location:http://xx.pro/post?s=1$lang_id"));
}
return "<iframe id='frame-one' scrolling='no' frameborder='0' style='".($_GET["type"] == "" ? "height:1640px;" : "height:1640px;")." width:100%;' src='http://xx.pro/post/index.php?view=".$_GET["view"]."&tx=".$_GET["tx"]."&st=".$_GET["st"]."&amt=".$_GET["amt"]."&type=".$_GET["type"]."$lang_id' ></iframe>";
}
}
?>
when I echo $session_start the output = GP:session_start and not 1
thx in advance

I think you assign the GP wrong, try it like this:
includeLibs.voucher = fileadmin/php/shop_init.php
lib.phpscript = USER
lib.phpscript.userFunc = voucher->init
lib.phpscript.userFunc.session_start_var = TEXT
lib.phpscript.userFunc.session_start_var.data = GP:session_start

Related

PHP If Value Equals 1 Then Define Variable, Else Do Nothing

Here's what I came up with and wondering if there is a more eloquent way to accomplish the below or if this is acceptable?
Update using Ternary Operators:
$fbpid = ($_GET['fbt'] == 1) ? ("123456") : (NULL);
echo $fbpid;
What I originally had:
$fbt = $_GET['fbt'];
if ($fbt == 1) {
$fbpid = "123456";
}
else {$fbpid = NULL;}
echo $fbpid;
$fbt = $_GET['fbt'];
$fbpid = null;
if ($fbt == 1)
{
$fbpid = "123456";
}
echo $fpbid;
// output: 123456

Show where is equal to 0 (PHP)

I have a form, and I want to validate it with PHP, for that I going to make just one if the problem is I want to detect where is the variable that equal to 0
My code
if(isset($_POST["submit"])){
$name = $_POST["name"];
$lname = $_POST["lname"];
if($name == "" || $lname == ""){
echo "Please, Enter All informations";
}
else {
$namepr = preg_match("/^[A-Za-z]{3,}$/",$name);
$lnamepr = preg_match("/^[A-Za-z]{3,}$/",$lname);
if($namepr == 0 || $lnamepr == 0){
<!-- here I want to select the variable that equal to 0 -->
}
else {
echo "Your name is : ".$name."<br>Your Last name is : ".$lname
}
}
}
my question is in the comment part, I want to show the variable equal to 0, I have two variable, I want to select the variable equal to 0
For your issue, you can use a ternary operator:
if($namepr == 0 || $lnamepr == 0){
$myVar = ($namepr == 0 ? $namepr : $lnamepr);
// do something with $myVar
}
or of course, a standard if block:
if($namepr == 0 || $lnamepr == 0){
if($namepr == 0){
$myVar = $namepr;
} else {
$myVar = $lnamepr;
}
// do something with $myVar
}

Putting a session in a if and else statement

I've got a problem with putting a session to store some page info into a variable
heres the code:
<?php
$t = $_GET['nm'];
if ($t=="1")
{
session_start();
// store session data
$_SESSION['nm']=1;
}
else
{
?>
<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
window.location = "http://www.gouda-info.nl/mobile";
}
</script>
<?php
}
$session = $_SESSION['nm'];
if ($session=="1")
{
When i try to use the script it just doesn't work. I use this script to redirect mobile users, but if they choose to use the Desktop version they'll be allowed by activating the session that stores if the user has activated the desktop version by putting nothing or a 1 in the link like so:
http://www.example.com/index.php?nm=1
hope anyone comes up with a bright solution. :)
EDIT:
it just fails if i try to run this code, it gives me a blank page.
session must be started on the top, and sometimes you deal with == 1 and other with $t == "1"
try this code:
// first line
session_start();
$t = $_GET['nm'];
if ($t == 1) { // use 1 instead of "1"
// store session data
$_SESSION['nm'] = 1;
} else {
?>
<script>
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
window.location = "http://www.gouda-info.nl/mobile";
}
</script>
<?php
}
$session = $_SESSION['nm'];
if ($session == 1) { // use 1 instead of "1"
}
You are using js code in php, but your js will be run after entire php file executed. So use php instead;
<?php
session_start();
$t = $_GET['nm'];
if ($t == "1") {
// store session data
$_SESSION['nm'] = "1";
} else {
if(isMobile()) {
header('Location: http://www.gouda-info.nl/mobile');
exit();
}
}
$session = $_SESSION['nm'];
if ($session == "1") {
......
}
function isMobile($user_agent=NULL) {
if(!isset($user_agent)) {
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
}
return (strpos($user_agent, 'Android') !== FALSE
|| strpos($user_agent, 'webOS') !== FALSE
|| strpos($user_agent, 'iPhone') !== FALSE
|| strpos($user_agent, 'iPad') !== FALSE
|| strpos($user_agent, 'iPod') !== FALSE
|| strpos($user_agent, 'BlackBerry') !== FALSE);
}

check my links format with php

I have something like this :
<?php
$siteurl = "http://www.example.com/";
$pageid = "ed2689";
$pageurl = $siteurl.$pageid;
?>
and the links will be like this:
http://www.example.com/ed2689
http://www.example.com/report/ed2689
I have used preg_match to check the format for each one of this links
for the first link, it must be exactly like this:
$siteurl.[a-z0-9]
and i have used this :
if (preg_match('/[$siteurl]+[a-z0-9]/', $pageurl) && !preg_match('/[=]|[?]/', $pageurl))
{
echo 'Ok',
}
and for for the second link, it must be exactly like this:
$siteurl.'report/'.[a-z0-9]
and i have used this :
if (preg_match('/[$siteurl]+[report]+[a-z0-9]/', $req_uri) && !preg_match('/[=]|[?]/', $req_uri))
{
echo 'Ok',
}
and it doesn't work correctly..any help please ?
Thanks.
Let me know if not works
<?php
$siteurl = 'http://www.example.com/report/ed2689';
//$siteurl = 'http://www.example.com/ed2689';
if(strpos($siteurl,'www.example.com') === false) echo 'not my site';
else {
$arr = explode('www.example.com/',$siteurl);
$suburl = trim($arr[1]);
if (preg_match('/^[a-z0-9]+$/', $suburl) || preg_match('/^report\/[a-z0-9]+$/', $suburl))
{
echo 'ok';
}
}
?>

if else simple beginner issue

Good day guys,
I've made a sweet favorites function with php mysql and ajax, and its working great. Now I want to show 'favorite' when favorite = 0 and show 'unfavorite' when favorite = 1
if ($favorites == 0) {
$favorite = 'Favorite';
}
if ($favorites == 1) {
$unfavorite = 'unFavorite';
}
and echo it in the row as :
<div id="favorites">' .($favorite). ' ' .($unfavorite). '</div>
The problem is: when favorite = 0, both $favorite and $unfavorite are being shown. When favorite = 1 only $unfavorite is being shown correctly. Of course it should be $favorite OR $unfavorite. I assume the problem is clear and simple to you, please assist :)
Thanks in advance
It's easier to use just one variable:
$text = ''
if ($favorites == 0) {
$text = 'Favorite';
} else {
$text = 'unFavorite';
}
...
echo $text;
If you want to check $favorite, you are using the wrong variable in your control statement. Also, it is better coding practice to use elseif rather than if for that second if. One more thing: it's easier to manage one resulting variable.
$output = "";
if ($favorite == 0) {
$output = 'Favorite';
}
elseif ($favorite == 1) {
$output = 'unFavorite';
}
...
echo $output; // Or whatever you want to do with your output
Is $favorites an integer?
Anyway try using three equal signs (===) or else instead of the second if:
if ( $favorites === 0 )
{
// ...
}
else // or if ($favorites === 1)
{
// ...
}
You're making a toggle, so you only need one variable:
if(empty($favourites)){
$fav_toggle = 'Favorite';
} else {
$fav_toggle = 'unFavorite';
}
echo $fav_toggle;
Same code is working on me if I assigned $favorites = 0; or $favorites = 1;
You can also use if else
$favorites = 1;
if ($favorites == 0) {
$favorite = 'Favorite';
}
else if ($favorites == 1) {
$unfavorite = 'unFavorite';
}

Categories