Custom PHP?

https://docs.wappler.io/t/logged-user-session-name/3319

Then the session name will be: siteSecurityId

So, for example in your custom PHP script you’ll be referring to it like: $_SESSION['siteSecurityId']

Searching in Forums & Documentation I don't see any follow up information on Using Custom PHP inside a php document made in Wappler.

And I haven't been able to use $_SESSION['siteSecurityId'] in the various normal ways of adding some custom php snippets.

Wappler seems to need a proprietary way exclusive to Wappler to embed Custom PHP

Any light to shed on this?

Thank you for your interest!

There is nothing to be documented. PHP code is ... PHP code :slight_smile: It doesn't matter if you write it in Notepad or Wappler.

Nope, that's not the case, there is no such a thing as "wappler way to run PHP"
What have you tried and what is not working?

That's not the name of the session $_SESSION['siteSecurityId'] as explained in the docs, the session name depends on the security provider step name. If it is called siteSecurity then the session name will be $_SESSION['siteSecurityId']
If it is called pizza the session would be $_SESSION['pizzaId'] ... etc.

I’m sorry to have given you the wrong information.

I was not using the generic code.

I’ve written PHP code for over 20 years.

One thing I know without a doubt is that PHP is NOT PHP!

I’ve been through tons of changes over 20 years.

There are a TON of factors that determine whether PHP will produce what you expect to display on a page.

Your attitude REALLY smokes my laptop at the moment, George.

Normal tried & tested methods of embedding PHP on my Wappler pages are coming up blank.

Wappler is Frameworks and Templates, too.
The code demands its own method of wrapping php & values from my experiments.

Do I have to go to file dependencies and put my php functions and Custom PHP there, first?

Or is this just too stupid of a question to get a civil response?

I'm sorry @NewMedia but from your posts in our community i just can't tell if you have ever written PHP or not, but that does not really matter here.

Then, what you have added is wrong.
That's why i asked you to provide the exact code which is not working.

Which have nothing to do with running some PHP code on a PHP page.

I still need this:

Btw it's Teodor, not George :slight_smile:

1 Like

Thank you, Teodor.

I’ve got to keep going on with what I have in front of me.
So, I must postpone this discussion until another day.

I’m used to using functions in php and then using those functions directly in a php page to output everything — if a dropdown list that pulls out all the necessary options is needed – php does it and you can go reference the functions and/ or classes on another page to modify or troubleshoot.

If you’re using templates then that changes the equation, so to speak, and you must customize your code to work with the built-in requirement of that particular template. PHP as usual methods fall apart when a template language must be interfaced.

My reaction to Wappler was to try and use the Click-click-click “visual” instructions from the start. But, the EXACT location & sequence of actions that are making up a Wappler page do usually make crucial differences in what variables are ready to be used, etc, etc.

So, now that I’ve been able to take some time to sort through all of the developmennt folders and generated “action steps” files associated with a page I can better see the flow of what is called for where & how these are defined.

I will never be a javascript .js query, etc, etc expert but I have a basic knowledge enough to do some troubleshooting with other tools.

Overall, though, it is the vast dependency on DMX extensions which make troubleshooting a bit tougher – You developers have a certain logical approach to how you created JS based solutions that is reflected in the proprietary DMX Zone javascript components.

For the time being I’m having to study the files that encompass what’s behind all of the click-clicks to the Visual approach.

Much obliged!

You don't really answer my question, but instead you mention some other things which i am really lost in. I am not sure how your last post is related to your initial question and what are you trying to explain or ask or comment.

In your first post you ask:

I asked you:

And no answer to this.

Please, can you stick to the topic and answer my question which is really specific and the answer should be really specific?
(example: I added xxxxxxxxxx on my page and the result is yyyyyyyyyy)

I use php code directly in Wappler all the time, well at least I used to, I think these days I enjoy the challenge of making things work without using my old trusty php, but anyway, here is some php to stick between the open and close body tags on a new test.php page and I just ran it, and it runs perfectly. So i’m not sure what you trying to do, but it would be great to see your visual php code that is not working, because I haven’t come across it yet.

<?php $execution_time = microtime(); // Start counting ?>

&copy; <?php echo date("Y"); ?><br /><br />

&copy; 2008-<?php echo date("Y"); ?><br /><br />

<?php function auto_copyright($year = 'auto'){ ?>
   <?php if(intval($year) == 'auto'){ $year = date('Y'); } ?>
   <?php if(intval($year) == date('Y')){ echo intval($year); } ?>
   <?php if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } ?>
   <?php if(intval($year) > date('Y')){ echo date('Y'); } ?>
<?php } ?>
<?php auto_copyright(); // 2020?><br />
<?php auto_copyright("2010");  // 2010 - 2020 ?><br /><br />

<?php if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) { ?>
  // You are viewing the HTTPS content
<?php } else { ?>
  // You are viewing the HTTP content
<?php } ?><br /><br />

<?php
  list($width, $height, $type, $attr) = getimagesize("https://www.apple.com/v/home/er/images/heroes/iphone-11-pro/hero__dvsxv8smkkgi_largetall_2x.jpg");

  echo "Image width " . $width;
  echo "Image height " . $height;
  echo "Image type " . $type;
  echo "Attribute " . $attr;
?><br /><br />

<?php
// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

// The Text you want to filter for urls
$text = "The text you want to filter goes here. http://google.com";
// Normal unfiltered text with a link
$text2 = "Some added text with a link to http://google.com";

// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {
    // make the urls hyper links
    echo preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>', $text);
    echo '<br />'.$text2;
} else {
    // if no urls in the text just return the text
    echo $text;
    echo '<br />'.$text2;
}
?><br /><br />

<?php $pageName = basename($_SERVER['PHP_SELF']); ?>
The name of this page is <?php echo $pageName; ?><br /><br />

<?php
    function getUrltest() {
        $urltest  = ( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"];
        $urltest .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
        $urltest .= $_SERVER["REQUEST_URI"];
        return $urltest;
    }
?>
<?php echo getUrltest(); ?><br /><br />

<?php
    function build_calendar($month,$year,$dateArray) {
        // Create array containing abbreviations of days of week.
        $daysOfWeek = array('S','M','T','W','T','F','S');

        // What is the first day of the month in question?
        $firstDayOfMonth = mktime(0,0,0,$month,1,$year);

        // How many days does this month contain?
        $numberDays = date('t',$firstDayOfMonth);

        // Retrieve some information about the first day of the
        // month in question.
        $dateComponents = getdate($firstDayOfMonth);

        // What is the name of the month in question?
        $monthName = $dateComponents['month'];

        // What is the index value (0-6) of the first day of the
        // month in question.
        $dayOfWeek = $dateComponents['wday'];

        // Create the table tag opener and day headers
        $calendar = "<table class='calendar'>";
        $calendar .= "<caption>$monthName $year</caption>";
        $calendar .= "<tr>";

        // Create the calendar headers
        foreach($daysOfWeek as $day) {
            $calendar .= "<th class='header'>$day</th>";
        }

        // Create the rest of the calendar

        // Initiate the day counter, starting with the 1st.

        $currentDay = 1;

        $calendar .= "</tr><tr>";

        // The variable $dayOfWeek is used to
        // ensure that the calendar
        // display consists of exactly 7 columns.

        if ($dayOfWeek > 0) {
            $calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>";
        }

        $month = str_pad($month, 2, "0", STR_PAD_LEFT);

        while ($currentDay <= $numberDays) {
            // Seventh column (Saturday) reached. Start a new row.
            if ($dayOfWeek == 7) {
                $dayOfWeek = 0;
                $calendar .= "</tr><tr>";
            }

            $currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT);

            $date = "$year-$month-$currentDayRel";

            $calendar .= "<td class='day' rel='$date'>$currentDay</td>";

            // Increment counters
            $currentDay++;
            $dayOfWeek++;
        }

        // Complete the row of the last week in month, if necessary
        if ($dayOfWeek != 7) {
            $remainingDays = 7 - $dayOfWeek;
            $calendar .= "<td colspan='$remainingDays'>&nbsp;</td>";
        }

        $calendar .= "</tr>";

        $calendar .= "</table>";

        return $calendar;
    }
?>
<?php echo build_calendar(01,2020); ?><br /><br />

<?php
    $execution_time = microtime() - $execution_time;
    printf('It took %.5f sec', $execution_time);
?>
1 Like

Beautiful Paul,

I will try this – you are putting this into a regular Wappler php page into the text content between the Open and Close body tags.

My code examples look like yours in that I was using the same open & close PHP tags and not even simple echo was working when I checked the browser page. PHP localhost was up and running. My page was “blahblah.php”

Thanks so much!

Okay, I’ll give that a go

Then you have some syntax errors most probably.

I must admit, I have used quite a bit of php code in Wappler that also wasn’t between the open and close body tags, they should work pretty much anywhere in your page, even if not between the open / close body tags.
Give it a try when you get a moment and see.

Wappler doesn’t show the PHP content in the design view, but it should work on the server and Wappler does nothing with your PHP code.

2 Likes

Using custom php is not a problem. The only reason that you could try recreate all code using Wappler way is to just be able visualuze everything in ServerConnect or AppConnect.

For example there are many times that I use a menu structure as an icluded file. In there I have several if statements that display diferreent structure based on SESSION id or User level as a SESSION variable.

Another example is a mutlilingual website where based on the ‘lang variable’ I display the results in a certain language.

All of us here we have some level of expertise in PHP and from the very first start of Wappler creation our main concern was to be able to add ‘custom code’. This is why Wappler is one of its kind. It is a tool that writes code that you can actually edit.

For anyone who is using Wappler creating everything though Wappler GUI is just a challenge and not an obligation, in order to make Wappler even more user friendly. But again Wappler has reached to a point that there is almost nothing that you cant do.

We all will be glad if something that can not be done is mentioned so it is added in future releases of Wappler.

Thank you!

1 Like

I use an API that allows me to get the real-time exchange rate of all currencies. I have embedded the code in my page, but using App Connect Bidding it does not retrieve the values (currency codes) which should calculate the conversion rate.

1 Like