Storing Php Code As A Variable

May 19, 2007

I would like to store php code into a variable, heres an example:

function test ($var) {
$var; //I also tried echo $var;

$string = "echo "test" ";
test ($string);

When it works, it will only output "echo test", instead of just "test".

View 3 Replies


Storing $_GET Variable In A Javascript Variable?

I am passing two pieces of info to a php page using the $_GET method (team1, team2). I'd like to use these as variables in some javascript. How can I do this?

View 7 Replies

Storing Content And Php Code

Bascially i am stating to use a MYSQL database to hold content for my site, i request the content at will depending what i need by doing a query. Now heres where i get the problem, some of my content has php code in it, how can i do this and make it run.

View 2 Replies

Preg_replace - Storing The Code In MySQL

I am putting a site together for my own reference, to take notes on php code, so I can go back later on and see how it is done. I am storing the code in MySQL. Obviously when I insert my code in to the database and pull this back out nothing is displayed.

For instance in this forum their is a small php tag you can use to enclose your php code before submitting. How does this work so when it displayed it looks like this below.
PHP Code:

<? echo "For example I enclosed this in the PHP tags before submitting to the database"; ?>

View 3 Replies

Storing Code In MySQL Column?

I'm working on a pet project and I'm looking for some hints/directions regarding best practices. I'm rolling my own blog that will display code snippets....similar to the code examples used in these posts and millions of others around the interweb. The code snippets are for display only and will never be retrieved and executed. I plan on using PDO and prepared statements for the database interactions. Is it ok to store this type of code in a database? Will PDO and prepared statements be sufficient for inserting into and selecting from columns that contain code snippets?

View 9 Replies

Storing Php Code In A Database (for Use With Eval)

I've got a need to store php code in my database (among the text) that I parse out and execute with eval(), and had it encrypted at first, but have seen now that the decryption process (it's a custom encryption/decryption function set) adds a good half second or so to an already-slow load time. Given that I've taken fairly adequate steps to securing my database, do you suppose there would be a problem storing the code as plain text to shave off that extra time?

View 6 Replies

Storing URL Value Into A Variable.

Is there any way to store url into a variable and then use the variable to send the user back to the same page from where he came.

View 7 Replies

Storing And Retrieving Code In Mysql Database?

I am working on a kind of CMS for my own website which no one else will be using but me as a way of improving my php skills, and am having problems with retrieving data from the database that holds both text and php code. I have searched the web and found that i should be using eval() for the code to be executed before it is send to the browser but cannot get it to work and can't find my mistake(s). the php code will always be the same, and is supposed to retrieve the id number of a page to use in a link (and works fine when tested by loading the code directly without retrieving it from the database) this is an example of data stored in the database


[Select]The<ahref="page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?>">Dwarven Mines</a> have a great selection of Ores,... Of course when I leave it like this, hovering over the link in my page will show exactly that and lead to nowhere

Code: [Select]localhost/page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?>

Most of these links appear in tips given at the end of the page and are processed as followed

Code:[Select]$questtips = $quest->getQuestTips();
$tips = "";
if ($questtips == "none")


I have tried all sorts to get the code to be executed when retrieved from the database before being send to the browser so that this particular link would say [URL[ but I cannot get it to work, though I suspect it is fairly easy. I suspect I would have to store the data in a different format in the database? And how exactly do I use the eval() function in my case?

View 6 Replies

Storing Current Url In A Variable

I want to store the current page url in variable $link

I used $link=$_SERVER['PHP_SELF'];

But it gave me only pages.php if the current link is [url]

This is required as i am storing the url in a social bookmarking site ...

View 1 Replies

Storing A Session Variable?

I have 5 forms. Each is an HTML page, that when the submit button is pressed, posts the data to a PHP page for processing (the viewer just gets taken to the next form). On the PHP page, the data is formatted and sent as an email. The problem is that the email address of the viewer is only asked for and entered on the first form, yet each of the five forms will send an email, and will need that viewers address as an $EmailFrom variable.

I wanted to pass just the email address from the first form where it is physically entered, to each of the other forms. I don't think that a "GET" method will work since there is way too many fields on the form and it will be too much data to pass in a url. I thought that storing a session variable would be my best bet. My thoughts were to put it in the first HTML page, and then destroy it in the last PHP page. But I have never done this, and have not had any luck yet. I put this code on my first HTML page, in between the DTD and the HTML tag:


Then I put this on the bottom of my PHP page:

$_SESSION['from']= $EmailFrom ;

Then on each of the remaining PHP pages, I entered this at the top:

$EmailFrom = $_SESSION['from'];

But the email address I see on the actual email I receive is:


View 5 Replies

Subtracting 1 From A Value And Storing It In Another Variable

I vaguely remember running into this problem before, but I'm wondering if this just doesn't work in PHP:

echo $counter; // outputs 4
$output = $counter--;
echo $output; // outputs 4

If I do something like:

$output = $counter - 1;

I have no problems whatsoever.

View 2 Replies

Storing Variable In Mysql

i have stored a variable into my database, i would like it to be a variable instead of being plain text, eg. i store $teazer in the db right, and then before i read the database i populate the vaiable $teazer rite, then i want it to come after a certain paragraph on some other page, so i figured the way to do it was to put it inside the db and it will be invoked by that variable.

View 3 Replies

Storing A Variable To A Session?

I have a form that the user selects a date and member id. I then update a table with that info and store the date to a session variable for use on another page. Everything works except the date doesn't store to the session variable.

if( is_array($member)){
$ddate = explode('/', $_POST['meeting_date']);
$sql_meeting_date = "$ddate[2]-$ddate[0]-$ddate[1]";


View 3 Replies

Storing A Database Value To A Variable?

Quotei want to store a value from a database and use it as variable in php code

in this code i want to store value of copies in a php variable

and want that it should be more than 0 (zero)

for furthur calculations

$update_book="update book set copies=copies-1 where bookid='$bookid'";
print "<html><body background="header.jpg">


View 1 Replies

Storing A Variable From A Function?

This seems really straight forward but I can't figure out why it's happening. As a part of an account registration script, I'm randomly generating a password using a function called, generatePassword($length,$strength);

I hash the password (md5) before putting it in the database but I also email the non-hashed version to the user. My problem is that each time I call the variable, it generates a new password so the one in the database does not match the one received by the user,

$user_password_plain = generatePassword($length,$strength);
$user_password = md5($user_password_plain);

Is there a different way to store the variable so that I can access it later in the script and it will be the same? I tried using a session variable but that didn't seem to work either.

View 10 Replies

Storing An Object In A Session Variable

Is it safe to store an object in a session variable, allowing it to be unserialized without the class definition loaded in some cases, then, later, unserialize with the class definition loaded and continue using normally? e.g.

page 1: load class definition, start session, create new object, store in session variable

page 2: start session, don't access object stored in session

page 3: load class definition, start session, access properties / methods of object stored in session

The PHP manual says

It is strongly recommended that you include the class definitions of all such registered objects on all of your pages . . . If you don't and an object is being unserialized without its class definition being present, it will lose its class association and become an object of class stdClass without any functions available at all . . .

What I am wondering is whether that explanation should be qualified by "for that request". That is, does unserializing the object without the class definition loaded only cripple the object for that request, or does it permanently damage it when it is reserialized?

I tried a quick, simple test by creating three pages that behave as described above, and it appeared to work fine.

View 6 Replies

Storing A Javascript Variable In A Php String

I have the following javascript function:

<script type="text/javascript">

function HTMLEncode( text )
text = text.replace(/&/g, "&amp;") ;
text = text.replace(/"/g, "&quot;") ;
text = text.replace(/</g, "&lt;") ;
text = text.replace(/>/g, "&gt;") ;
text = text.replace(/'/g, "'") ;
return text ;

Now I want to store the content of 'text' in a php string.
Is that possible?

View 3 Replies

Join Two Variable Storing String ?

I want to join $pass1 & $pass2 variables and store it in variable $pass3.

$pass1=substr($str1, 0, 2);
$pass2=substr($str2, 0, 2);

View 2 Replies

Storing A URL String Into A Session Variable

I'm wondering is there is a way to store the URL of a page into a session variable. I would then use this to create a hyperlink to the page.

View 1 Replies

Storing Part Of A String In A New Variable

I have a string (usually a url as it happens) which I need to get a certain part of and then store it in a variable. i.e.

my strings are like this: ""

So basically the URL or String are the same except for the numbers change. It is the numbers I want to store in a new variable.

I think I need to use regular expressions and preg_replace but just can't get my head around how!.

View 1 Replies

Storing A Loop As A String In A Variable?

I have a problem storing a PHP loop in a variable.

The loop is like this:

for( $i = 1; $i <= 10; $i++ ) {

echo $i . ' - ';

for this it's OK for an echo or print as it will produce:

1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 -

now I want to store the whole loop in a variable like $my_var which means:

echo $my_var;

which will produce:

1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 -

the whole idea is that I want to make the loop, store it as a string in a variable $my_var, than use it later in my script.

View 1 Replies

Storing $_Session Variable In Class?

I want to be able to store a $_SESSION variable from my class but it does not seem to be working. I searched stackoverflow and googled for quite some time and was not able to find sufficient information to know whether this is possible or not.

Can I store a $_SESSION variable in my class? I cant seem to access it outside of the class.

class myClass {
public function authorizeLogin($email,$password) {
global $_SESSION;
//Query to authorize user
$q_auth = $this->query("
SELECT first_name,last_name,email,date_registered,access_id
FROM users
WHERE email = '$email' AND password = '$password'");

View 2 Replies

Using Curl And Storing Cookie As Variable?

i have a curl function that visits a website, logs in to said website, stores the cookie file, then can later read the cookie file to visit a page that would normally require a login. problem i am faced with is i want to save and retrieve the cookie file using a php variable but cant seem to get it to work.


i assume the syntax is wrong, and not that curl cant handle a variable as a location?

View 1 Replies

Storing A Object In A Session Variable?

I'm writing one of my first classes. I work for an insurance broker and am trying to use a Class to store things about a quote, and store the Object as a session variable. Thing is, when I view the session variables, I get:

__PHP_Incomplete_Class Object


View 2 Replies

Storing Last_insert_id() In A Session Variable?

In my project i wanna use the last_insert_id() to be stored in a session variable and after that i wanna use that session variable i.e., the value of last_insert_id() in another page. How can i carry the last_insert_id() to some other page using session or storing it in a session variable ?

View 3 Replies

Storing Data From Mysql As Variable?

I got my code (below) basically it is to resend user activation email if they for some reason or other did not get it first time etc. It sends the email and everything etc... what i need to do it not only get the user email address which i can do no problem but to also fetch the user activation key and username from the DB. Now if you look in my code i put

$query = ("SELECT * FROM userinformation WHERE `email` = '$email', `username` = ' ', `activationkey` = ' ' ");

the email part of it works as it checks the email address the user put in form against the DB but the activationkey and username part it does not get from DB. I need to get the activation key from DB and username to as it needs to be stored in a variable like the email so it is sent along with the email. Problem is like i said the activation key and username is not being fetched from DB.


View 9 Replies

Copyrights 2005-15, All rights reserved